Reputation: 2317
Hi I am trying to reload a pie of Highcharts in this way:
$("#Actualizar").click(function(){
$.ajax({
url:'ajax/core/Ajax_Request.php',
type:'POST',
dataType:'json',
data:{
AppRequest:'Dashboard/htmlPies',
params: { 'params':{'orden':'orden'}}
},
success:function (result) {
chart.series[0].setData(result);
}
});
});
In the server side I have this.
$resultado=array(100, 1000, 400, 200);
echo json_encode($resultado);
And it is working, but what I want is to add the this.point.name like this
$resultado=array('a'=>100, 'b'=>1000, 'c'=>400, 'd'=>200);
echo json_encode($resultado);
Now it does not draw anything.
The original js to fill the data is like this
data: [
['Firefox', 45.0],
['IE', 26.8],
['Chrome', 12.8],
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
Thanks.
Upvotes: 0
Views: 98
Reputation: 6356
Note that your data
in JavaScript is an array which contains lots of two item arrays. To mimic this in PHP:
$resultado=array(array('a', 100), array('b', 1000), array('c', 400), array('d', 200));
More likely, you'll want to do this in a loop, e.g.:
$resultado = array();
$dataItems = array('a'=>100, 'b'=>1000, 'c'=>400, 'd'=>200);
foreach ($dataItems as $key => $value) {
$resultado[] = array($key, $value);
}
There's probably a more efficient way to do this earlier in your code, and build the data structure appropriately . . .
Upvotes: 1