Fusioncharts - update FusionCharts data without changing chart settings

Is there a way to set the "data" property for Fusionchart only. Since at present, when you install the data in the last step, you need to pass a complete json object that has both the "data" and the "chart" properties.

Below is my sample code;

FusionCharts.ready(function () { var ageGroupChart = new FusionCharts({ id: 'total-users', type: 'pie2d', renderAt: 'chart-container', width: '450', height: '300', dataFormat: 'json', "chart": { "caption": "Sample Graph", "enableSmartLabels": "0", "showPercentValues": "1", "showTooltip": "0", "decimals": "1", "theme": "ocean" }, "data":null }); ageGroupChart.setJSONUrl( "http://www.example.com/GetData.php" ); ageGroupChart.render(); }); 

As you can see, I am installing data from an online source. I would prefer that the online source does not send the "chart" property along with the data. Therefore, I can separate the appearance of the user interface from the data source.

Any ideas?

+5
source share
1 answer

I use the following function through XLMhttpRequest calls:

 function updateChart(data) { var jsonData = { "chart": { // Some rendering options "caption": caption, "subcaption": "" }, "data": data }; // First time I initialize my chart if (FusionCharts("myChartId") === undefined) { var chart = new myChartId({ // Some rendering options swfUrl: "Charts/MSLine.swf", id: "myChartId", width: "100%", height: "280px", dataFormat: 'json' }); chart.setJSONData(jsonData); chart.render("myContainerId"); } else // Then I just update FusionCharts("myChartId").setJSONData(jsonData); } 

I call the updateChart function in my callback:

 success: function(data, request) { try { var d = JSON.parse(data); updateChart(d.chart); // Other job... var event = new CustomEvent("dataReceivedFromAjax", {"detail": d}); document.dispatchEvent(event); } catch (e) { window.console.warn("Wrong format JSON data received"); window.console.warn(data); } } 

Of course, you can adapt my code to your case (for example, I use JsonData , not JsonUrl ).

+2
source

Source: https://habr.com/ru/post/1201136/


All Articles