Chart is a pure JS plug-in, it is powerful and small to use is very simple.
The first step is to introduce chart.js.
<script type= "Text/javascript" src= "<%=path%>/js/mapping/chart.js" ></script>
The second draw control style can be defined by itself but the ID cannot be changed
<canvas id= "Canvas" height= "width=" ></canvas>
The third step configuration parameter//If it is multiple data comparison, copy multiple datasets separated by commas but the value of datasets data to pass a different
var linechartdata = {
Labels:monthyear,//labels is the x-axis parameter, such as 201601,201602, is a JS array. Remember that it must be a JS string array
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:usercnt2//This is the y-axis parameter is the exact value, say 201602 months. Production value is 30,000 pieces this is a JS array of values
}
]
};
Fourth Step Call function
Graph
function Diagram () {
var ctx = document.getElementById ("Canvas"). GetContext ("2d");
Window.myline = new Chart (CTX). Line (Linechartdata, {
Responsive:true
});
};
Bar chart
function Barchart () {
var ctx = document.getElementById ("Canvas"). GetContext ("2d");
Window.myline = new Chart (CTX). Bar (Linechartdata, {
Responsive:true
});
};
Which chart do you need to call directly
Bar chart
Barchart ();//This will do it.
In addition to the Java list assignment of a JS array method, I loop list the fields I need to stitch my string comma separated and then uploaded to the page
var month= ' ${month} ';//month
var monthyear=month.split (",");//Date string array
var cnt= ' ${cnt} ';
var usercnt=cnt.split (",");//Number of strings array
var usercnt2=new Array (); ;//Declare a blank array
for (var i = 0; i< usercnt.length; i++) {
Usercnt2[i]=parseint (Usercnt[i]);//assignment to an array of values
}
JS Chart Plugin chart.js