ChartJS设置默认轴

时间:2014-09-15 03:34:40

标签: javascript php jquery charts chart.js

我在我的网站上开发ChartJs,但问题是我无法设置我的行图表的轴,所以任何人都可以帮助解决这个问题吗?

这是我当前图表的视图:

enter image description here

这是我的图表代码:

var lineChartData = {
    labels : ["00:00","06:00","12:00", "18:00"],
    datasets : [{
        labels: "PR",
        fillColor : "rgba(247, 70, 74, 0.1)",
        //fillColor : "rgba(220,220,220,0.2)",
        strokeColor : "rgba(220,220,220,1)",
        pointColor : "rgba(220,220,220,1)",
        pointStrokeColor : "#FF0040",
        pointHighlightFill : "#fff",
        pointHighlightStroke : "rgba(220,220,220,1)",
        data : [65,59,90,81,56,55,40]
    }, {
        label: "QTY",
        fillColor : "rgba(0, 0, 255, 0.1)",
        //fillColor : "rgba(151,187,205,0.2)",
        strokeColor : "rgba(151,187,205,1)",
        pointColor : "rgba(151,187,205,1)",
        pointStrokeColor : "#0000FF",
        pointHighlightFill : "#fff",
        pointHighlightStroke : "rgba(151,187,205,1)",
        data : [28,48,40,19,96,27,100]
    }]
}

我想在我的图表中显示的是轴的值 在当前图表中显示0,20,30,40,50,...,100

我希望它将默认设置为0,25%,50%,75%,100%

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

http://jsfiddle.net/qsosLya0/

诀窍是以下配置选项:

var lineChartOptions = {
  scaleOverride: true,
  scaleSteps: 4,
  scaleStepWidth: 25,
  scaleStartValue: 0,
  scaleLabel: "<%=value%>%"
};

来源:http://www.chartjs.org/docs/#getting-started-global-chart-configuration