gpt4 book ai didi

javascript - 在 ChartJS 上仅显示整个单位

转载 作者:行者123 更新时间:2023-12-02 15:21:28 25 4
gpt4 key购买 nike

我今天正在制作一个图表 - 来测试它 - 我在想是否可以在图表一侧仅显示整个单位? (如 1 2 3 4 5 6 7 8 9 等等...)我正在使用 ChartJS

这是一个屏幕: enter image description here

(单位位于左侧,靠近“值”)

PS:请原谅我的英语不好,我是法国人。

最佳答案

我也有这个问题,但是当我查看chartjs的代码时,我可以理解发生了什么,发生这种情况是因为数据集中的最小值和最大值只有在数据集有大于1的值时才会显示在1之间只是整数部分,请参阅代码片段:

var lineChartData1 = {
"datasets": [{
"data": [
"0.5",
"0.2",
"0.9",
"0.4",
"0.3",
"0.2",
"0.5",
"0.7",
"0.5",
"1"],
"pointStrokeColor": "#fff",
"fillColor": "rgba(155,220,220,0.5)",
"pointColor": "rgba(155,220,220,1)",
"strokeColor": "rgba(155,220,220,1)"
}],
"labels": [
"2013-01-01",
"2013-01-04",
"2013-01-15",
"2013-02-03",
"2013-03-25",
"2013-04-03",
"2013-04-14",
"2013-05-27",
"2013-05-27",
"2013-08-03"]
};

var lineChartData2 = {
"datasets": [{
"data": [
"0.5",
"0.2",
"3",
"0.4",
"0.3",
"2.2",
"2",
"0.7",
"0.5",
"1"],
"pointStrokeColor": "#fff",
"fillColor": "rgba(155,100,220,0.5)",
"pointColor": "rgba(155,100,220,1)",
"strokeColor": "rgba(155,100,220,1)"
}],
"labels": [
"2013-01-01",
"2013-01-04",
"2013-01-15",
"2013-02-03",
"2013-03-25",
"2013-04-03",
"2013-04-14",
"2013-05-27",
"2013-05-27",
"2013-08-03"]
};


var myLine = new Chart(document.getElementById("canvas1").getContext("2d")).Line(lineChartData1);
var myLine2 = new Chart(document.getElementById("canvas2").getContext("2d")).Line(lineChartData2);
<script src="http://www.chartjs.org/assets/Chart.js"></script>

<body>
<div>
<h3>Only one Integer</h3>
<canvas id="canvas1" height="200" width="400"></canvas>
</div>
<div>
<h3>More then one Integer</h3>
<canvas id="canvas2" height="200" width="400"></canvas>
</div>
</body>

希望对你有用。

关于javascript - 在 ChartJS 上仅显示整个单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34005757/

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