Reputation: 827
My chart freezes when its data are updated and also when downloading chart to client. Below is my updating process.
FusionCharts.setCurrentRenderer('JavaScript');
FusionCharts.ready(function () {
var chart = new FusionCharts({
type: "dragcolumn2d",
renderAt: "chartWeightAnalysis",
id: "dragChartId",
width: '100%',
height: '500',
dataSource: "compute/" +<?php echo $_SESSION['MM_Username']; ?> + "renderChartDragColumn2d.xml",
dataFormat: "xmlurl",
events: {
'chartUpdated': function (evt, args) {
var diffWeight = args.startValue - args.endValue;
var resultXML = chart.getXMLData();
var result = JSON.stringify(chart.getData());// alert(chart.getData());
var newString = jQuery.parseJSON(result);
var weightBox = [];
var sum = 0;
var resultBox = [];
var allDataBox = [];
jQuery.each(newString, function (key, value) {
if (key !== 0 && key !== args.dataIndex) {
weightBox.push(value[1]);
sum += value[1];
}
});
for (var key in weightBox)
{
var ratio = (weightBox[key] * diffWeight / sum);
var newValue = ratio + weightBox[key];
resultBox.push(newValue);
allDataBox.push(weightBox[key], newValue);
}
var dataIndex = (args.dataIndex - 1) * 2;
allDataBox.splice(dataIndex, 0, args.startValue, args.endValue);
var matrix = listToMatrix(allDataBox, 2);
for (var key in matrix) {
resultXML = resultXML.replace('value="' + matrix[key][0] + '"', 'value="' + matrix[key][1] + '"');
}
UpdateChart(chart, resultXML);
}
}
}).render();
});
}
function UpdateChart(chart, resultXML) {
chart.setXMLData(resultXML);
}
(source: soft-touchdigital.com)
Once it renders, it becomes unresponsive. what could be the issue? Also exporting a chart to client causes it to freeze likewise.
Upvotes: 0
Views: 222
Reputation: 827
I found the answer, I realized that the error was from the setChartData function in general, if you use a different setChartData type it become unresponsive. for instance in my about code, I used datasouce: as a url to XML(setXMLUrl equivalent) and later wanted to update using setXMLData in turn created an error. Look at the update code; I used ajax to save the updated date to the same file (Important!!!).
function UpdateChart(resultXML) {
$.ajax({
type: "POST",
async: false,
url: "app_processor.php",
data: {action: "DragChartUpdate", getXMLData: resultXML},
success: function (msg) {
if (msg !== 0)
{
chart.setXMLUrl("compute/" +<?php echo $_SESSION['MM_Username']; ?> + "renderChartColumn2d.xml");
}
}
});
}
in my php file:
function DragChartUpdate($getXMLData) {
if (isset($getXMLData)) {
file_put_contents("compute/" . $_SESSION['MM_Username'] . "renderChartColumn2d.xml", "<?xml version='1.0' encoding='utf-8'?>" . $getXMLData . "");
} else {
file_put_contents("compute/" . $_SESSION['MM_Username'] . "renderChartColumn2d.xml", "<?xml version='1.0' encoding='utf-8'?>");
}
}
Upvotes: 2