Javascript Chart.js 比例修复
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21514984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Chart.js scale fix
提问by testerius
I have a simeple question about Chart.js, I would like to know how can I fix my chart.
我有一个关于 Chart.js 的简单问题,我想知道如何修复我的图表。
I use Chart.js and respChartJS (https://github.com/arifLogic/respChartJS)
我使用 Chart.js 和 respChartJS ( https://github.com/arifLogic/respChartJS)
Demo: http://jsfiddle.net/k3YH7/1/
演示:http: //jsfiddle.net/k3YH7/1/
var data = {
labels : ["Something #1","Something #2","Something #3"],
datasets : [
{
fillColor : "rgba(224, 34, 34, 0.5)",
strokeColor : "#830505",
data : [1500,1500,1500]
}
]
}
respChart($("#chart2"),data);
Well, these bars so small and do not work as I expected. How can I make it visible? I want to crate better scale for example: 500, 1000, 1500, 2500 etc.
好吧,这些条太小了,不像我预期的那样工作。我怎样才能让它可见?我想创造更好的规模,例如:500、1000、1500、2500 等。
回答by LM.Croisez
For drawing my chart.Line with a fixed Y axis scale, I use this code:
为了使用固定的 Y 轴比例绘制我的 chart.Line,我使用以下代码:
mychart.Line(data,{scaleOverride: true, scaleStartValue: 0, scaleStepWidth: 1, scaleSteps: 30});
This should also work for the chart.Bar object.
这也适用于 chart.Bar 对象。
回答by ardev
Check these answers out:
看看这些答案:
chartjs : how to set custom scale in bar chart
how to change the Y-axis values from real numbers to integer in chartjs?
Basically you'd add this to your datasets (where n is the number of scale steps you want):
基本上,您会将其添加到您的数据集中(其中 n 是您想要的比例步数):
scaleOverride:true,
scaleSteps:n,
scaleStartValue:0,
scaleStepWidth:500,