I have a JSON object with the following structure:
[{
"Codigo": 7,
"Descricao": "Atividade 1",
"CodigoMilestone": 6,
"TempoRevisado": 2,
"Inicio": "\/Date(1445738400000)\/",
"InicioCedo": "\/Date(1445738400000)\/",
"InicioTarde": "\/Date(-62135589600000)\/",
"TerminoCedo": "\/Date(1445911200000)\/",
"TerminoTarde": "\/Date(-62135589600000)\/",
"Ativo": true,
"Milestone": null,
"Dependencia": [],
"Dependencia1": []
}, {
"Codigo": 8,
"Descricao": "Ativade 2",
"CodigoMilestone": 6,
"TempoRevisado": 2,
"Inicio": "\/Date(1445997600000)\/",
"InicioCedo": "\/Date(1445997600000)\/",
"InicioTarde": "\/Date(1445911200000)\/",
"TerminoCedo": "\/Date(1446084000000)\/",
"TerminoTarde": "\/Date(1446084000000)\/",
"Ativo": true,
"Milestone": null,
"Dependencia": [],
"Dependencia1": []
}]
I need to model so that the code below receives the values of this object:
"dataProvider": [ {
"milestone": "Infraestrutura",
"atividade": [ {
"InicioCedo": 1,
"TempoRevisado": 2,
"color": "#7B742C",
"Descricao": "Instalar Banco de Dados"
}, {
"InicioCedo": 3,
"TempoRevisado": 2,
"color": "#7E585F",
"Descricao": "Instalar Visual Studio"
}]
} ],
The full code is here: JS Fiddle
It should look something like this, it's that I do not master Javascript
var atividades =
[{
"Codigo":7,
"Descricao":"Atividade 1",
"CodigoMilestone":6,
"TempoRevisado":2,
"Inicio":"\/Date(1445738400000)\/",
"InicioCedo":"\/Date(1445738400000)\/",
"InicioTarde":"\/Date(-62135589600000)\/",
"TerminoCedo":"\/Date(1445911200000)\/",
"TerminoTarde":"\/Date(-62135589600000)\/",
"Ativo":true,
"Milestone":null,
"Dependencia":[],
"Dependencia1":[]
}]
if (atividades != null) {
var dataprovider = '';
$.each(atividades, function (key, val) {
dataprovider += '"dataProvider": [ {'
'"milestone":' + val.CodigoMilestone,
'"atividade": [ {'
'"InicioCedo":' + val.InicioCedo + ',' +
'"TempoRevisado":' + val.TempoRevisado + ',' +
'"color": "#7B742C",'
'"Descricao":' + val.Descricao +
'}]'
'}],'
})
}
AmCharts.useUTC = true;
var chart = AmCharts.makeChart( "chartdiv", {
"type": "gantt",
"theme": "dark",
"marginRight": 70,
"period": "bb",
"dataDateFormat":"DD-MM-YYYY",
"balloonDateFormat": "JJ:NN",
"columnWidth": 0.5,
"valueAxis": {
"type": "month",
"minimum": 1,
"maximum": 30
},
"brightnessStep": 10,
"graph": {
"fillAlphas": 1,
"balloonText": "<b>[[Descricao]]</b>: [[open]] [[value]]"
},
"rotate": true,
"categoryField": "milestone",
"segmentsField": "atividade",
"colorField": "color",
"startDate": "01-10-2015",
"startField": "InicioCedo",
"endField": "TerminoCedo",
"durationField": "TempoRevisado",
**dataprovider** // aqui ficaria a estrutura que está sendo construida no JAVASCRIPT
"chartScrollbar": {},
"chartCursor": {
"valueBalloonsEnabled": false,
"cursorAlpha": 0.1,
"valueLineBalloonEnabled": true,
"valueLineEnabled": true,
"fullWidth": true
},
"export": {
"enabled": true
}
} );