Question

My webpage have 3 chart(Line chart and Stacked column chart)

each chart have different series

but have same length of data

the length of data and categories are fetch from database

it mean i can't set a default setting

i use the below javascript to set these charts

    //loop Chart1, 2, 3
    $.each(Charts, function(i,chart){

        //loop series
        $.each(chart.series, function (i, se) {

            //set series default data e.g[0, 0, 0, 0, 0]
            se.setData(Series);

        });

        //set categories e.g["Peter", "John", "Tom", "Mary", "May"]
        chart.xAxis[0].setCategories(Categories);

    });

* the problem is spend a long time and maybe cause the browser "No responding".

Was it helpful?

Solution

Try to replace your code with

$.each(Charts, function(i,chart){

    //loop series
    $.each(chart.series, function (i, se) {

        //set series default data e.g[0, 0, 0, 0, 0]
        se.setData(Series,false);

    });

    //set categories e.g["Peter", "John", "Tom", "Mary", "May"]
    chart.xAxis[0].setCategories(Categories,false);
    chart.xAxis[0].isDirty = true;
    chart.redraw();
});

OTHER TIPS

Nested loops are terrible for performance. Pre-process your data so that you can just provide the appropriate series to each chart.

Depending on how often the data refreshes in the database use the appropriate levels of caching on the database, on the server-side that retrieves the data from the database, and on the on the web-server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top