You must be logged in to post your query.
Home › Forums › Chart Support › Montando array
Tagged: javascript
Estou tentando montar uma array partir de um banco de dados, mas esta dando um erro:
`function ChartIndicadorAgrupado() {
var A = [], B = [], C = [], D = []; var TA = [], TB = [], TC = [], TD = []; var v1 = 0, v2 = 0, v3 = 0, v4 = 0,v5 = 0; var Valor = []; var VDepto = []; var Local = $(‘#Unidade’).val(); var evento = “?$select=Depto,Evento&$filter=(Unidade%20eq%20′” + Local + “‘)&$top=999999&$orderBy=Depto” var dados = GetListItems(‘6002862F-1E0E-4442-A95B-96235C460CA0’, evento); var Eventos = [“Acidente Típico (Afast. > 15 dias)”, “Acidente Típico (Afast. <= 15 dias)”, “Ocorrência Típica”, “Atendimento Ambulatorial”, “Quase Acidente”]
Eventos.forEach(function (itemA) { dados.forEach(function (itemB) { if (itemB.Evento == itemA) { Valor[v1] = itemB; VDepto[v1] = itemB.Depto; v1++; } }); });
VDepto = […new Set(VDepto)];
VDepto.forEach(function (itemA) { v1 = 1; for (var itemB = 0; itemB < Valor.length; itemB++) {
if (itemA == Valor[itemB].Depto && Valor[itemB].Evento == “Quase Acidente”) { v1 = v1 + 1; } else if (itemA == Valor[itemB].Depto && Valor[itemB].Evento == “Atendimento Ambulatorial”) { v1 = v1 + 1; } }
A[v2] = ‘{x:’ + itemA + ‘,y:”‘ + v1 + ‘”}’; v2++;
B[v3] = ‘{x:’ + itemA + ‘,y:”‘ + v1 + ‘”}’; v3++;
C[v4] = ‘{x:’ + itemA + ‘,y:”‘ + v1 + ‘”}’; v4++;
D[v5] = ‘{x:’ + itemA + ‘,y:”‘ + v1 + ‘”}’; v5++;
})
TA = “[“+ A +”]”; TB = “[“+ B +”]”; TC = “[“+ C +”]”; TD = “[“+ D +”]”;
//A[v1] = ‘{y:’ + v1 + ‘,label:”‘ + itemB.Depto + ‘”}’;
document.getElementById(‘myChartAgrupadoC’).innerHTML = ”; document.getElementById(‘myChartAgrupadoC’).innerHTML = ‘<div id=”myChartAgrupado” style=”width:100%”></div>’
var chart = new CanvasJS.Chart(“myChartAgrupado”, { animationEnabled: true,
data: [{ type: “stackedColumn”, toolTipContent: “{x}:{y}”, indexLabel: “{y}”, showInLegend: true, name: “Quase Acidente”, color: “blue”, dataPoints: A, }, { type: “stackedColumn”, toolTipContent: “{x}:{y}”, indexLabel: “{y}”, showInLegend: true, name: “Atendimento Ambulatorial”, color: “Yellow”, dataPoints: B, }, { type: “stackedColumn”, toolTipContent: “{x}:{y}”, indexLabel: “{y}”, showInLegend: true, name: “Ocorrência Típica”, color: “Orange”, dataPoints: C, }, { type: “stackedColumn”, toolTipContent: “{x}:{y}”, indexLabel: “{y}”, showInLegend: true, name: “Acidente Típico”, color: “Red”, dataPoints: D, } ] });
chart.render();
}’
@valdecirrk,
Can you kindly create JSFiddle / Working Sample Project reproducing the issue you are facing and share it with us (You can share Sample Project over Google-Drive / Onedrive), so that we can run it at our end, understand the issue better and help you out?
— Vishwas R Team CanvasJS
You must be logged in to reply to this topic. Login/Register