Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

HighchartsReact download chart to PNG/SVG/IMG from js code

I’m trying to use Highcharts React to export the chart as any kind of image (jpg, png, svg..).

I’ve read, that Highcharts-React creates another instance for exporting. So there’s no getSVG() function on the Highcharts Ref.

Is there any way to get the image via code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const App = () => {
  const chartComponent = useRef(null);

  const printChartAsImage = () => {
    // chart to image
    const chart = chartComponent.current.chart;
    console.log(chart.getSVG());
  };

  return (
    <>
      <button onClick={printChartAsImage}>Print visible page</button>
      <div id="element-to-print">
        <HighchartsReact
          highcharts={Highcharts}
          options={chartOptions}
          ref={chartComponent}
        />
      </div>
    </>
  );
};

>Solution :

You are missing the Highcharts exporting module:

import Highcharts from "highcharts";
import exportingModule from "highcharts/modules/exporting";

exportingModule(Highcharts);

Live demo: https://codesandbox.io/s/highcharts-react-demo-fork-cmmwwg?file=/demo.jsx

Docs: https://www.highcharts.com/docs/export-module/export-module-overview

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading