在Chart.JS上设置限制

时间:2014-09-04 14:49:19

标签: javascript charts chart.js

有没有办法在chart.js中硬编码min最大Y轴?我已经在小提琴中进行了基本设置,但是在插件的文档中没有看到任何内容。

在第二个注释中,有没有办法阻止这样的东西不占用整个画布?我想在60像素上扫描图形并将图像放在那里。

编辑:

http://jsfiddle.net/cf1pfyg3/

这是我目前的代码!

    var randomScalingFactor = function(){ return Math.round(Math.random()*100)};

var barChartData = {
    labels : ["Zinc","Boron","Sulphur","Potassium","Nitrogen","Aluminium","Iron"],
    barstroke: true,
    datasets : [
        {
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,0.8)",
            highlightFill: "rgba(220,220,220,0.75)",
            highlightStroke: "rgba(220,220,220,1)",
            data : [1,2,3,4,5,6,7]
        },

    ]

}

    var ctx = document.getElementById("canvas").getContext("2d");
    window.myBar = new Chart(ctx).Bar(barChartData, {
        barstroke: true,
        responsive : true
    });

1 个答案:

答案 0 :(得分:1)

稍微挖掘一下他的来自做文档:

 var randomScalingFactor = function(){ return Math.round(Math.random()*100)};

var barChartData = {
    labels : ["Zinc","Boron","Sulphur","Potassium","Nitrogen","Aluminium","Iron"],
    barstroke: true,
    datasets : [
        {
            fillColor : "rgba(220,220,220,0.5)",
            strokeColor : "rgba(220,220,220,0.8)",
            highlightFill: "rgba(220,220,220,0.75)",
            highlightStroke: "rgba(220,220,220,1)",
            data : [1,2,3,4,5,6,7]
        },

    ]

}
window.onload = function(){
    var ctx = document.getElementById("canvas").getContext("2d");
    window.myBar = new Chart(ctx).Bar(barChartData, {
        barstroke: true,
        responsive : true,
        // Boolean - If we want to override with a hard coded scale
        scaleOverride: true,

        // ** Required if scaleOverride is true **
        // Number - The number of steps in a hard coded scale
        scaleSteps: 14,
        // Number - The value jump in the hard coded scale
        scaleStepWidth: 1,
        // Number - The scale starting value
        scaleStartValue: 0
    });
}