kyletraynorn
Posts: 1
Joined: Wed May 11, 2022 5:29 pm

getDataRows per chart?

Hi,

I am overriding getDataRows, in order to change the data before export to xls.
https://api.highcharts.com/class-refere ... etDataRows

My problem is that I have many charts on the page, and I want to be able to run a different function for each chart, however setting it once seems to effect all of them.

How do I set a different getDataRows per chart instead of universally? I am using Typescript with Angular, each chart is in a different angular component.

Code: Select all

    Highcharts.Chart.prototype.getDataRows = (multiLevelHeaders) => {
      var rows = [["Age Group", "Distrobution"]]
      for (let i = 0; i < this.aggregatedData.length; i++) {
        if (this.aggregatedData[i].ageGroup) {
          rows.push([this.aggregatedData[i].ageGroup, this.aggregatedData[i].distribution.toString()])
        }
      }
      return rows;
    };

Also, as a separate note, this documentation here seems to say that exportData is called and intended for this purpose, however as far as I can tell, this never gets called during export to xls, and others on stackoverflow seem to acknowledge this inconsistency.
https://api.highcharts.com/highcharts/c ... exportData
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: getDataRows per chart?

Hi kyletraynorn,
Welcome to our forum and thanks for contacting us with your question!

To extend the getDataRows function you should use a H.wrap method and do something with your data. In this wrap, you can differentiate which function should be called - just like in the first demo.

In my opinion better solution to change the data before exporting to XLS would be using the exportData event, which is called during export to XLS and works correctly. The argument passed in that event is an object with dataRows storing all data rows. You can see it in the second demo.

Demo with H.wrap: https://stackblitz.com/edit/highcharts- ... ine-wmohgk
Demo with exportData event: https://stackblitz.com/edit/highcharts- ... ine-xttwzp
API Reference: https://www.highcharts.com/docs/extendi ... highcharts

Let me know if that was what you were looking for!
Best regards!
Hubert Kozik
Highcharts Developer

Return to “Highcharts Usage”