Javascript Chart.js scale fix

2019-06-18 16:05发布

问题:

I have a simeple question about Chart.js, I would like to know how can I fix my chart.

I use Chart.js and respChartJS (https://github.com/arifLogic/respChartJS)

Demo: 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.

回答1:

For drawing my chart.Line with a fixed Y axis scale, I use this code:

mychart.Line(data,{scaleOverride: true, scaleStartValue: 0, scaleStepWidth: 1, scaleSteps: 30});

This should also work for the chart.Bar object.



回答2:

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):

  scaleOverride:true,
     scaleSteps:n,
     scaleStartValue:0,
     scaleStepWidth:500,