http://blog.csdn.net/wsk7860/article/details/8751061
Recently to do a project, the project manager want to do a statistical report, on the Internet to check some information on the selection of highchars here and you share the use of experience.
It is important to note that this code displays multiple item comparisons for a single report.
Direct Paste code: Web Side
<script type= "Text/javascript" src= "Js/jquery/jquery-1.7.2.js" ></script>
<script type= "Text/javascript" src= "Js/highcharts/highcharts.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
var options = {
Chart: {
Renderto: ' container ',//div container ID
Type: ' column '//report type
},
Report Name
title:{
Text: ' Test '
},
//Supplemental Notes
Subtitle: {
Text: ' Report description '
},
YAxis: {
min:0,
Title: {
Text: ' Unit (mm) '
}
},
X-Axis display content
Xaxis: {
Categories: []
},
//Data sources (multiple comparisons)
Series: [{},{},{},{}]
};
JSON URL address I use the servlet here
var url = "Http://127.0.0.1:8080/servlet/JsonServlet";
$.getjson (url,function (data) {
var i,len=data.length;
for (i=0;i<len;i++) {
//Assignment Series
options.series[i].data = Data[i]. list;
options.series[i].name = data[i].name;
Assign a value to a report x axis display name
Options.xaxis.categories[i]=data[i].year;
}
var chart = new Highcharts.chart (options);
});
});
</script>
<body>
<div id= "Container" ></div>
</body>
Background servlet doget () method content:
Response.setcharacterencoding ("UTF-8");
Response.setcontenttype ("text/html");
Jsonarray members = new Jsonarray ();
PrintWriter out= Response.getwriter ();
try {
for (int i=1;i<5;i++) {
Building a JSON object
Jsonobject member = new Jsonobject ();
Parameters required to build series
Member.put ("name", "Zhang Fei" +i); corresponding Series.Name
Jsonarray list = new Jsonarray ()//corresponds to Series.data
for (int k=1;k<5;k++) {
List.put (k*100);
}
Member.put ("Year", (+ i));//corresponding y axis display
Member.put ("list", list);
Member.put ("Color", "#FF0022"), or you can set a histogram color if you want
Members.put (member);
}
Out.write (Members.tostring ());
catch (Jsonexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Out.flush ();
Out.close ();
Picture for effect Chart: