Advice on improving calculation speed of data for HighCharts

Advice on improving calculation speed of data for HighCharts

cj1005cj1005 Posts: 142Questions: 45Answers: 1

Hi All,

I have highcharts working with my datatable and it looks great, the only issue I'm having is the calculation of the data for the chart is taking 10+ seconds on 6500+ records, so every time a user does a search or sorts a column it takes that long.

Below is the offending section of my function. What I'd like to know is, is there a faster\better way of achieving this? (Atm server-side is not an option).

For clarity, column 2 of the datatable is the month and year (i.e. 'June 21' or 'December 20') and column 6 is the sales value of that row. So, my function is summing up the total sales for each month+year and putting it into an array for highcharts to use.

var monthTO = {};
var indexes = TurnoverRepoTable.rows({ search: 'applied' }).indexes().toArray();
for (var i = 0; i < indexes.length; i++) {
    var cMonth = TurnoverRepoTable.cell(indexes[i], 2).data();
    var value = TurnoverRepoTable.cell(indexes[i], 6).data();
    if (monthTO[cMonth] === undefined) {
        monthTO[cMonth] = Number(value);
    } else {
        monthTO[cMonth] = monthTO[cMonth] + Number(value);
    }
}

Thanks, Chris

This question has an accepted answers - jump to answer

Answers

  • cj1005cj1005 Posts: 142Questions: 45Answers: 1

    One idea is to gather the data from columns 2 and 6 at the same time I generate the 'indexes' array, something like:

    var indexes = TurnoverRepoTable.rows({ search: 'applied' }).indexes().data(2,6).toArray();
    

    Although, I'm not sure if that is possible or how I would go about doing this :neutral:

  • cj1005cj1005 Posts: 142Questions: 45Answers: 1

    I have found the solution, I'm now referencing the data directly rather than by indexes, latest code below:

    var dataset = TurnoverRepoTable.rows({ search: 'applied' }).data().toArray();
    for (var i = 0; i < dataset.length; i++) {
        var cMonth = dataset[i].job.cMonth
        var value = dataset[i].job.estout
        if (monthTO[cMonth] === undefined) {
            monthTO[cMonth] = Number(value);
        } else {
            monthTO[cMonth] = monthTO[cMonth] + Number(value);
        }
    }
    
  • colincolin Posts: 15,143Questions: 1Answers: 2,586
    Answer ✓

    Glad you got it working, thanks for reporting back,

    Colin

Sign In or Register to comment.