stor314
Posts: 2
Joined: Thu Sep 29, 2022 2:59 pm

How to only export viewable data to csv/xlsx?

Is there a way to have highcharts only export the current viewable data in the chart to csv/xlsx? Currently it exports the entire dataset for the series, where I only want it to export what the user sees.

The only solutions I've seen require you to modify a Highcharts prototype function in order to allow this functionality like shown here http://jsfiddle.net/2Jyn5/251/

But there's gotta be a different way than that right? I really would prefer not to have do it that way, opens up a lot of maintainability issues and just doesn't seem like a clean solution.

Or maybe, is there a way to set a min and max for an axis on export? I tried modifying the following before export but it didn't do anything:

Code: Select all

chart.options.exporting.xAxis = {min: minDate};
Thanks
stor314
Posts: 2
Joined: Thu Sep 29, 2022 2:59 pm

Re: How to only export viewable data to csv/xlsx?

Found the answer here viewtopic.php?t=43899

Code: Select all

    (function(H) {
        H.wrap(H.Chart.prototype, 'getDataRows', function(proceed, multiLevelHeaders) {
            var rows = proceed.call(this, multiLevelHeaders),
                xMin = this.xAxis[0].min,
                xMax = this.xAxis[0].max;

            rows = rows.filter(function(row) {
                return typeof row.x !== 'number' || (row.x >= xMin && row.x <= xMax);
            });

            return rows;
        });
    }(Highcharts));
hubert.k
Posts: 1164
Joined: Mon Apr 11, 2022 11:48 am

Re: How to only export viewable data to csv/xlsx?

Hi stor314!
It's great to hear, that you managed it on your own! Thank you for sharing the solution with other users, maybe someone in the future will face the similar issue as yours :)
In case of any further questions, feel free to contact us again.
Hubert Kozik
Highcharts Developer

Return to “Highcharts Usage”