How to add export functionality to custom button in React highcharts?

亡梦爱人 提交于 2020-01-24 16:37:11

问题


I have this project in which I am trying to implement export highchart functionality from out side of the chart.

Is there any way I can achieve that? I am using React highcharts and the download formats are Jpeg and CSV.

Thanks in advance


回答1:


I found an solution using functional components:

First import the modules:

import * as Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';

require('highcharts/modules/exporting')(Highcharts);
require('highcharts/modules/export-data')(Highcharts);

Then create a ref to the chart:

  const chart = useRef();
....
....
<HighchartsReact ref={chart} highcharts={Highcharts} options={chartOptions} />

Then create a method like this one, triggered by a click event:

  const downloadCSV = () => {
    if (chart && chart.current && chart.current.chart) {
      chart.current.chart.downloadCSV();
    }
  };


来源:https://stackoverflow.com/questions/58098067/how-to-add-export-functionality-to-custom-button-in-react-highcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!