charts.js line scaleOverride scaleSteps scaleStepWidth 动态图表高度及间隔单位

      有的没的 2014-8-26 14:01:00

 <!doctype html>

<html>
<head>
<title>Line Chart</title>
<script src="../Chart.js"></script>
</head>
<body>
<div style="width:60%">
<div>
<canvas id="canvas" height="450" width="960"></canvas>
</div>
</div>
 
<script>
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var randomScalingFactor2 = function(){ return Math.round(Math.random()*80)};
var randomdata = [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
var randomdata2 = [randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2(),randomScalingFactor2()]
var scaleStepss = 20;
// var max = Math.max.apply(null,randomdata);
var max = 1000
var scaleStepWidths = Math.floor(max / scaleStepss) + 1;
var Ymax = scaleStepWidths * scaleStepss;
var lineoption = {
scaleOverride : true,
scaleSteps : scaleStepss,
       scaleStepWidth : scaleStepWidths,
       scaleStartValue : 0,
       responsive: true,
     }
var lineChartData = {
labels : ["January","February","March","April","May","June","July","January","February","March","April","May","June","July","January","February","March","April","May","June","July"],
datasets : [
{
label: "My First dataset",
fillColor : "rgba(220,220,220,0.2)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
data : randomdata
},
{
label: "My Second dataset",
fillColor : "rgba(151,187,205,0.2)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(151,187,205,1)",
data : randomdata2
}
]
 
}
 
 
 
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx).Line(lineChartData, lineoption);
}
 
 
</script>
</body>
</html>
 
标签集:TAGS:
回复Comments() 点击Count()
喜欢就顶一下

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}