2014/08/26 | charts.js line scaleOverride scaleSteps scaleStepWidth 动态图表高度及间隔单位
类别(有的没的) | 评论(0) | 阅读(446) | 发表于 14:01

 <!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>
 
0

评论Comments

日志分类
首页[193]
flash As[107]
有的没的[59]
数码照片[4]
自由世界[19]
blender[4]