1

I am looking to add Y-Axis Min & Max values to the exported csv file from a Highstocks graph. I haven't been able to find a solution to it. Please let me know if there is one. Thanks!

My chart

Duplicate min/max values

1 Answers1

0

You can wrap the getCSV method and modify returned CSV. For example:

(function(H) {
    H.wrap(H.Chart.prototype, 'getCSV', function(proceed) {
        const csv = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
        const yAxis = this.yAxis[0];

        return csv + ';Min: ' + yAxis.min + ' Max: ' + yAxis.max;
    });
})(Highcharts);

Live demo: http://jsfiddle.net/BlackLabel/9muv3kpo/

Docs: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

ppotaczek
  • 36,341
  • 2
  • 14
  • 24
  • Hey thanks for the help. This seems to be working. However, I seem to have stumbled into another issue here. The wrapped function seems to be running multiple times and is printing multiple copies of the return statement in the csv file. Just wanted to ask what might be causing this abnormal behaviour? – Daniyal Yahya Oct 10 '22 at 12:59
  • Hi @Daniyal Yahya, This can happen if you wrap the function more than once, simplified example: http://jsfiddle.net/BlackLabel/p4dehzu0/ Please make sure that the wrap is added only once. – ppotaczek Oct 10 '22 at 13:24
  • I'm wrapping the function only once. Using an exact replica of the code snippet you sent above but it's calling the function exactly 4 times. Is it possible to edit the csv through the options of a chart? Somewhere around here maybe: https://api.highcharts.com/highcharts/exporting.csv – Daniyal Yahya Oct 11 '22 at 06:46
  • I am using typescript - react btw. I missed out on this point, thought I'd let you know – Daniyal Yahya Oct 11 '22 at 06:56
  • No, it is not possible to do that through the API. Please reproduce the problem in some online code editor. You can use this example: https://codesandbox.io/s/highcharts-react-demo-forked-yi81d?file=/demo.jsx as a base to start. – ppotaczek Oct 11 '22 at 12:36
  • https://codesandbox.io/s/highcharts-react-demo-forked-ku29yh?file=/demo.jsx This is somewhat, how I've coded my options in highcharts to be. I have also edited the question and added an image to show what my chart looks like – Daniyal Yahya Oct 12 '22 at 07:34
  • I've added the wrap to your code and everything works as expected. Live example: https://codesandbox.io/s/highcharts-react-demo-w636fu?file=/demo.jsx – ppotaczek Oct 12 '22 at 08:46