FusionChart图表更新冻结图表

时间:2016-02-02 15:59:29

标签: javascript fusioncharts

我的图表在其数据更新时以及将图表下载到客户端时冻结。以下是我的更新过程。

 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);
        }

a busy cat http://soft-touchdigital.com/images/errorChart.png

一旦呈现,它就会变得没有反应。可能是什么问题? 同时将图表导出到客户端会导致它同样冻结。

1 个答案:

答案 0 :(得分:2)

我找到了答案,我意识到错误来自setChartData函数,如果你使用不同的 setChartData 类型,它会变得无法响应。例如,在我的代码中,我使用 datasouce:作为XML的URL setXMLUrl 等价物),后来想要依次使用 setXMLData 进行更新造成了一个错误。查看更新代码;我使用ajax将更新日期保存到 相同文件 (重要!!!)。

            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");
                            }
                        }
                    });

                }

在我的php文件中:

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'?>");
   }
 }