//显示统计图
function showChart(){
var dateType = $("input[name='dateType']:radio:checked").val();
var result = getChartData(dateType);
// alert(result);
//result 是json格式字符串
// var result = "{\"chart\": [{\"categories\": \"1,2,3,4\",\"data\": \"22.1,33.5,44.5,55\"}]}";
//处理json
var resultArray= eval('(' + result + ')');
//x轴: categories
var categories= (resultArray.chart[0].categories).split(",");
//整个图的宽度:width;多的话则允许x轴滚动条
var width ;
//name
var name ;
if(dateType == "y"){
name = "按年统计";
}else if(dateType == "q"){
name = "按季统计";
}else if(dateType == "m"){
name = "按月统计";
}else if(dateType == "d"){
name = "按日统计";
width = 2800;
}else{
name = "统计";
}
//data
var dataTmp = (resultArray.chart[0].data).split(",");
var data = new Array(dataTmp.length);
for(x in dataTmp){
data[x] = Number(dataTmp[x]);
}
//图
var chart;
$(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'resultId', //放置图表的DIV的id属性
defaultSeriesType: 'column' ,
width: width
},
colors:['#0000FF','#4572A7'],
title: {
text: 'XXX分布图'
},
subtitle: {
text: '按时间统计'
},
xAxis: {
categories: categories
},
yAxis: {
min: 0,
title: {
text: 'XXX数 (个)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.0f} </b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: name,
data: data
}]
});
});
}