2014-09-04 84 views
0

有沒有辦法在chart.js中對min和max軸進行硬編碼?我已經在小提琴中獲得了基本設置,但是在插件的文檔中沒有看到任何內容。在Chart.JS上設置限制

在第二個注意,有沒有辦法來防止這樣的事情不佔用整個畫布?我想在可能的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 
    }); 
+0

請發表您的當前代碼:^) – 2014-09-04 14:51:02

+0

我忘了,謝謝! – henonChesser 2014-09-04 14:59:10

回答

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 
    }); 
} 
+0

很酷,如果這個問題得到解答,您可以將自己的答案標記爲答案,以便人們知道這是解決方案。 – Quince 2014-09-05 09:03:31

+0

@Quince我仍然可以在大約24小時前得到答案。同時,還有不止一種方式來給貓換膚。我不介意聽到其他的想法。我只能回答主要問題。 – henonChesser 2014-09-05 12:45:44

+0

非常真實(關於貓)酷只是確保你知道(我現在意識到你是):) – Quince 2014-09-05 12:50:05