gpt4 book ai didi

javascript - 图表.js?特别是雷达图表和负数

转载 作者:行者123 更新时间:2023-12-05 01:22:40 27 4
gpt4 key购买 nike

我是 JavaScript 的新手,使用 chart.js 的雷达图,但每次我在图表数据上输入负数时,我总是得到变形的图像。

代码在这里:

var radarChartData = {
labels: [
"Soccer",
"Basketball",
"Swimming",
"Volleyball",
"Computer games",
"Tennis",
],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [-3,7,6,6,4,6]
},

]
};


window.onload = function(){
window.myRadar = new Chart(document.getElementById("canvas").getContext("2d")).Radar(radarChartData,
{
responsive: true
});
}

最佳答案

1/要将实际值更改为整数,您可以使用:

var intvalue = Math.floor( floatvalue );
var intvalue = Math.ceil( floatvalue );
var intvalue = Math.round( floatvalue );

2/对于变形图像:试试 Math.abs(val);

关于javascript - 图表.js?特别是雷达图表和负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29763289/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com