简体   繁体   English

如何将 Highchart 变量饼图的图像存储到变量中并传递给 React-PDF

[英]How do I store an image of a Highchart variable pie chart into a variable and pass to React-PDF

I was wondering if someone could help me.我想知道是否有人可以帮助我。 I need to be able to pass through a PNG or SVG of my Highcharts VariablePie chart to @react-pdf/render I am using highcharts-react-official package to render my highchart in my react application.我需要能够通过我的 Highcharts VariablePie 图表的 PNG 或 SVG 到 @react-pdf/render 我正在使用highcharts-react-official ZEFE90A8E604A7C840E88D03A677F 在我的 reactB 应用程序中渲染 high.

I have react-pdf installed - https://react-pdf.org/我已经安装了react-pdf - https://react-pdf.org/

I have my page where my Highchart variable pie renders with other content, then a button that will download a PDF.我有我的页面,其中我的 Highchart 变量饼图与其他内容一起呈现,然后是一个按钮,它将下载 PDF。 This is created using React-PDF I somehow need to pass an Image of my Highchart VariablePie chart.这是使用 React-PDF 创建的,我不知何故需要传递我的 Highchart VariablePie 图表的图像。 I have seen posts about chart.getSVG() and base64 but how do you use this in highcharts-react-official ?我看过有关 chart.getSVG() 和 base64 的帖子,但是你如何在highcharts-react-official中使用它? could someone show me an example using functional components and hooks, and how would you convert it to a PNG and store that as a variable that I can use to pass through to react-pdf有人可以向我展示一个使用功能组件和钩子的示例,以及如何将其转换为 PNG 并将其存储为我可以用来传递给 react-pdf 的变量

  1. List item get a image of highcharts variablepie chart (no downloading or export)列表项获取 highcharts 变量饼图的图像(无需下载或导出)
  2. store as a variable in the application作为变量存储在应用程序中
  3. to pass through to react-pdf通过 react-pdf

is there a way to do this?有没有办法做到这一点? could someone help and show me an example?有人可以帮我举个例子吗? Thank you谢谢

To use chart.getSVG method in React, you need to add exporting module and get the chart component reference.要在 React 中使用chart.getSVG方法,您需要添加exporting模块并获取图表组件引用。 For example:例如:

import HighchartsReact from "highcharts-react-official";
// Import Highcharts
import Highcharts from "highcharts";
import HCExporting from "highcharts/modules/exporting";

HCExporting(Highcharts);

const Chart = () => {
  const chartComponent = useRef(null);
  const [options] = useState(...);

  useEffect(() => {
    const chart = chartComponent.current.chart;
    const chartSVG = chart.getSVG();

    console.log(chartSVG);  
  }, []);

  return <HighchartsReact ref={chartComponent} highcharts={Highcharts} options={options} />;
};

Live demo: https://codesandbox.io/s/highcharts-react-demo-fork-bwk8nq?file=/demo.jsx现场演示: https://codesandbox.io/s/highcharts-react-demo-fork-bwk8nq?file=/demo.jsx

API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#getSVG API 参考: https://api.highcharts.com/class-reference/Highcharts.Chart#getSVG

Docs: https://www.npmjs.com/package/highcharts-react-official#how-to-get-a-chart-instance文档: https://www.npmjs.com/package/highcharts-react-official#how-to-get-a-chart-instance

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM