stor314
stor314

Reputation: 419

Highcharts 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:

chart.options.exporting.xAxis = {min: minDate};

Thanks

Upvotes: 0

Views: 282

Answers (1)

stor314
stor314

Reputation: 419

If anyone sees this in the future, you can extend the getDataRows function by wrapping it and restricting the row axes

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

Upvotes: 1

Related Questions