You can reverse legend order by parameter: reversed
HighCharts Data and Legend Ordering
-
13-07-2023 - |
Pergunta
I set up a HighChart to look at a MySQL database via a JSON feed, however the problem I have is that if the stacked column chart displays January to December from left to right the Legend shows it in reverse order December to January left to right.
Having tried to re-order the series in the code and poking around on the HighCharts information I am at a dead end.
Is this correctable, and if so could you let me know what to change please? Thanks.
Here's my code:
<?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);
?>
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow