问题
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