继承我的data.php代码。此代码只会获取没有特定月份和年份的数据。现在我想要的是将月份下拉列表(例如1月 - 12月)与当前年份放在一起,如果我从下拉列表中选择一个月,则图表也会更改数据。
<?php
$con = mysql_connect("localhost","root");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bfp", $con);
$query = mysql_query("select city, sum(Miscellaneous) as Miscellaneous,
sum(Residential) as Residential, sum(Assembly) as Assembly, sum(Educational) as `Educational, sum(Institutional) as Institutional, sum(Mercantile) as Mercantile, sum(Business) as Business, sum(Industrial) as Industrial, sum(Storage) as Storage, sum(Mixed) as Mixed, sum(total) as total from report_structure group by city ");`
$category = array();
$category['name'] = 'City';
$series1 = array();
$series1['name'] = 'Business';
$series2 = array();
$series2['name'] = 'Storage';
$series3 = array();
$series3['name'] = 'Residential';
$series4 = array();
$series4['name'] = 'Assembly';
$series5 = array();
$series5['name'] = 'Educational';
$series6 = array();
$series6['name'] = 'Institutional';
$series7 = array();
$series7['name'] = 'Mercantile';
$series8 = array();
$series8['name'] = 'Industrial';
$series9 = array();
$series9['name'] = 'Miscellaneous';
$series10 = array();
$series10['name'] = 'Mixed';
while($r = mysql_fetch_array($query)) {
$category['data'][] = $r['city'];
$series1['data'][] = $r['Business'];
$series2['data'][] = $r['Storage'];
$series3['data'][] = $r['Residential'];
$series4['data'][] = $r['Assembly'];
$series5['data'][] = $r['Educational'];
$series6['data'][] = $r['Institutional'];
$series7['data'][] = $r['Mercantile'];
$series8['data'][] = $r['Industrial'];
$series9['data'][] = $r['Miscellaneous'];
$series10['data'][] = $r['Mixed'];
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
array_push($result,$series3);
array_push($result,$series4);
array_push($result,$series5);
array_push($result,$series6);
array_push($result,$series7);
array_push($result,$series8);
array_push($result,$series9);
array_push($result,$series10);
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
结束data.php
这是我的structure.php数据加载。任何人都可以帮助我吗?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Bar chart with data from MySQL using Highcharts</title>
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
height: 400,
width: 1000,
renderTo: 'container',
type: 'column'
},
title: {
text: 'Consolidated Fire Incident by Structure in each Station',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
min: 0,
title: {
text: 'Requests'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: false,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: []
}
$.getJSON("data.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
options.series[2] = json[3];
options.series[3] = json[4];
options.series[4] = json[5];
options.series[5] = json[6];
options.series[6] = json[7];
options.series[7] = json[8];
options.series[8] = json[9];
options.series[9] = json[10];
chart = new Highcharts.Chart(options);
});
});
</script>
<script src="highcharts.js"></script>
<script src="exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 800px; margin: 0 auto"></div>
</body>
</html>
答案 0 :(得分:1)
你可以用两种不同的方式来做。
将整个数据按月保存为单独的数据集。追加他们制作一整年的数据。当用户选择下拉列表中的任何月份时,更新系列数据或重新呈现图表
您可以对xAxis使用setExtremes()方法,具体取决于下拉列表中选择的月份。
如果用户从6月1日到6月30日选择june set xAxis extremes。
希望这会对你有所帮助