My goal is to utilize amcharts for displaying data retrieved from my server. Unfortunately, the API format doesn't align directly with amCharts. It seems that I need to utilize the postProcess function to preprocess the data, but I am struggling due to the lack of error messages and my limited experience in javascript.
Following their instructions, here is where I currently stand:
var chart = AmCharts.makeChart( "$CHART$", {
"type": "serial",
"legend": {
"horizontalGap": 10,
"maxColumns": 1,
"position": "right",
"useGraphSettings": true,
"markerSize": 10
},
"dataLoader": {
"format": "json",
"postProcess": function( data, config, chart ) {
var newData = [];
for ( var i = 0; i < data.rows.length; i++ ) {
var dataPoint = {};
dataPoint= data["items"];
newData.push( dataPoint );
}
return newData;
},
"showCurtain": true,
"showErrors": true,
"url": "*url*",
"headers": [{
"key": "Accept",
"value": "application/javascript, application/json",
"Authorization":"Basic *encodedpassword*"
}]
}, "categoryField": "timestamp",
"graphs": [ {
"valueField": "value",
"bullet": "round",
"bulletBorderColor": "#6698FF",
"bulletBorderThickness": 2,
"bulletAlpha":0,
"bulletSize":0,
"title":"ServerData",
"lineThickness": 2,
"lineColor": "#6698FF",
"lineAlpha": 0.5,
"fillAlphas": 0.8,
"fillColors":"#6698FF",
} ],
"valueAxes": [{
"axisAlpha": 0,
"dashLength": 5,
"gridCount": 10,
"position": "left",
"unit": "V",
}],
"categoryAxis": {
"minPeriod": "mm",
"labelsEnabled": false
},
"chartCursor": {
"oneBalloonOnly": true,
"zoomable":true
},
} );
The sample output returned from the server's API is provided below:
{"href":"*url/value*","offset":0,"limit":20,"items":[
{"stateVarId":"value1","timestamp":1523939135978,"value":887.0},
{"stateVarId":"value1","timestamp":1523935535977,"value":887.0},{"stateVarId":"value1","timestamp":1523845535955,"value":887.0}]}
In order for amCharts to interpret the values correctly, they should not be nested inside the "items":[ ...] section.
Therefore, the postProcess function must navigate the JSON format and extract the contents of "items".
If you require additional information, please feel free to reach out. I will gladly provide any missing details.
Thank you.