我设置了一个HighChart来通过JSON提要来查看MySQL数据库,但是我遇到的问题是,如果堆积柱形图从左到右显示1月到12月,那么图例会以相反的顺序显示它从12月到1月离开向右。
我试图在代码中重新排序系列并在HighCharts信息上探讨我的死路一条。
这是否可以纠正,如果是这样,你能告诉我要改变什么吗?谢谢。
这是我的代码:
<?php
$con = mysql_connect("***","***","***");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("***", $con);
$query = mysql_query("SELECT * FROM viewByMonth");
$category = array();
$category['name'] = 'variety';
$series1 = array();
$series1['name'] = 'Jan';
$series2 = array();
$series2['name'] = 'Feb';
$series3 = array();
$series3['name'] = 'Mar';
$series4 = array();
$series4['name'] = 'Apr';
$series5 = array();
$series5['name'] = 'May';
$series6 = array();
$series6['name'] = 'Jun';
$series7 = array();
$series7['name'] = 'Jul';
$series8 = array();
$series8['name'] = 'Aug';
$series9 = array();
$series9['name'] = 'Sep';
$series10 = array();
$series10['name'] = 'Oct';
$series11 = array();
$series11['name'] = 'Nov';
$series12 = array();
$series12['name'] = 'Dec';
while($r = mysql_fetch_array($query)) {
$category['data'][] = $r['variety'];
$series1['data'][] = $r['Jan'];
$series2['data'][] = $r['Feb'];
$series3['data'][] = $r['Mar'];
$series4['data'][] = $r['Apr'];
$series5['data'][] = $r['May'];
$series6['data'][] = $r['Jun'];
$series7['data'][] = $r['Jul'];
$series8['data'][] = $r['Aug'];
$series9['data'][] = $r['Sep'];
$series10['data'][] = $r['Oct'];
$series11['data'][] = $r['Nov'];
$series12['data'][] = $r['Dec'];
}
$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);
array_push($result,$series11);
array_push($result,$series12);
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
?>