data.php is returning:
{name: 'orcamento', data: [14000.00,8500.00,0.00]},{name: 'real', data: [2038.00,120.00,15000.00]},{name: 'desvio', data: [-11962.00,-8380.00,15000.00]}
I want to use this data to feed a chart. If I type the following code, it works well:
$(document).ready(function(){
var options={
chart: {
renderTo:'container',
type: 'bar'
},
title: {
text: 'Total Anual'
},
xAxis: {
categories: ['Vendas', 'Serviços', 'Outras']
},
series: [{name: 'orcamento', data: [14000.00,8500.00,0.00]},{name: 'real', data: [2038.00,120.00,15000.00]},{name: 'desvio', data: [-11962.00,-8380.00,15000.00]}]
};
});
But the following code doesn't work:
$(document).ready(function(){
var options={
chart: {
renderTo:'container',
type: 'bar'
},
title: {
text: 'Total Anual'
},
xAxis: {
categories: ['Vendas', 'Serviços', 'Outras']
},
series: [$.get('data.php')]
};
});
Why?
EDIT: I also tried this without luck:
$(document).ready(function(){
var dados=[];
$.ajax({
url:'data.php',
success: function(response){
dados=response
}
});
var options={
chart: {
renderTo:'container',
type: 'bar'
},
title: {
text: 'Total Anual'
},
xAxis: {
categories: ['Vendas', 'Serviços', 'Outras']
},
series: [dados]
};
});
EDIT2: Also tried the following but I get an empty chart:
$(document).ready(function(){
var dados=[];
$.ajax({
url:'data.php',
success: function(response){
dados=response
},
async:false
});
var options={
chart: {
renderTo:'container',
type: 'bar'
},
title: {
text: 'Total Anual'
},
xAxis: {
categories: ['Vendas', 'Serviços', 'Outras']
},
series: [dados]
};
var chart = new Highcharts.Chart(options);
});
In JSONLint, I get the error:
Parse error on line 1:
{ name: 'orcamento',
-----^
Expecting 'STRING', '}'
[]around your entire JSON structure. Second, you can load async result into a variable like you are attempting to do, you need to set options.series from within a success callback to$.get()