我想开发一个条形图,在X轴上会有一些关于行号的数据。在我的图表中,我想显示日期间隔。假设将有一个开始日期和结束日期。我做过这样的事情:
1.我的连接页面(demo.php)是这样的:
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("demo_planning", $con);
$query = mysql_query("SELECT alocate_line, sewing_end, sewing_start FROM demo_input");
$category = array();
$category['name'] = 'Line';
$series1 = array();
$series1['name'] = 'Sewing End';
$series2 = array();
$series2['name'] = 'Sewing Start';
while($r = mysql_fetch_array($query)) {
$category['data'][] = $r['alocate_line'];
$series1['data'][] = str_replace("-",",",$r['sewing_end']);
$series2['data'][] = str_replace("-",",",$r['sewing_start']);
}
$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
我的高级图表页面就像那样:
<script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'bar',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'INPUT',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Requests'
},
plotLines: [{
value: 0,
width: 3,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: []
}
$.getJSON("data_demo.php", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
chart = new Highcharts.Chart(options);
});
});
</script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 600px; margin: 0 auto"></div>