Good afternoon, it's my first question here.
I'm getting the json below through an ajax request.
[
{"SEMANA":1.0,"PRODUCAO":0.0,"PRODUCAO2":0.0},
{"SEMANA":2.0,"PRODUCAO":29280.0,"PRODUCAO2":55992.0},
{"SEMANA":3.0,"PRODUCAO":93864.0,"PRODUCAO2":75072.0},
{"SEMANA":4.0,"PRODUCAO":135625.0,"PRODUCAO2":102480.0}
]
I convert JSON to array as follows:
$.get("caminho do WebService", function (dados) {
var arrSemana = [],
arrProd1 = [],
arrProd2 = [];
for (var i = 0; i < dados.length; i++) {
arrSemana.push(dados[i].SEMANA);
arrProd1.push(dados[i].PRODUCAO);
arrProd2.push(dados[i].PRODUCAO2);
}
//......
});
But at the time I'm going to check out this my array (arrSemana, arrProd1, arrProd2)
is thus [,,,,,,,,]
and not with values as I would like [1.0, 2.0, 3.0]
I'm creating graphics with highChart so I need this array.
Where am I wrong that he is not picking up the values as I need them? Does anyone have an example that can help me?
Thank you for your attention.
I'm working with Apache Cordova (PhoneGap). I need to put this in 3 array so I can put it on the chart.
$ (function () {$ .get ("WebService path", function) {
var arrSemana = [],
arrProd1 = [],
arrProd2 = [];
for (var i = 0; i < dados.length; i++) {
arrSemana.push(dados[i].SEMANA);
arrProd1.push(dados[i].PRODUCAO);
arrProd2.push(dados[i].PRODUCAO2);
}
// Os alerts estão aqui para teste...
alert(dados);
alert(arrSemana);
alert(arrProd1);
alert(arrProd2);
$('#chart').highcharts({
title: {
text: 'Produção semanal de açúcar (registrada)',
x: -20 //center
},
subtitle: {
text: 'Dados: Teste de Relatório',
x: -20
},
xAxis: {
title: {
text: 'Semanas'
},
categories: arrSemana, //Um array vem aqui...
minTickInterval: 5,
minRange: 0,
min: 0
},
yAxis: {
allowDecimals: false,
title: {
text: 'Produção'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: 'un'
},
legend: {
layout: 'vertical',
align: 'middle',
verticalAlign: 'bottom',
borderWidth: 0
},
series: [{
name: 'Semanas 12/13',
color: '#32CD32',
data: arrProd1 // Outro array vem aqui...
}, {
name: 'Semanas 13/14',
color: '#000000',
data: arrProd2 // Outro array vem aqui...
}]
});
)) fail (function () { alert ("Error loading report data."); }); });