EvHaus / react-pdf-charts

Allows SVG-based React charts to be rendered in react-pdf
MIT License
53 stars 3 forks source link

Fails to render BarChart #416

Closed adel121 closed 3 months ago

adel121 commented 3 months ago

Describe the bug

Currently, when trying to embed a Barchart, it fails with the following error:

[react-pdf-charts]: Your chart rendered a <p /> node which isn't supported by <ReactPDFChart /> yet. Please report this issue.
    at Object.replaceHtmlWithPdfSvg [as replace] (http://localhost:3000/static/js/bundle.js:340521:13)
    at domToReact (http://localhost:3000/static/js/bundle.js:130001:36)
    at Object.replaceHtmlWithPdfSvg [as replace] (http://localhost:3000/static/js/bundle.js:340345:86)
    at domToReact (http://localhost:3000/static/js/bundle.js:130001:36)
    at Object.replaceHtmlWithPdfSvg [as replace] (http://localhost:3000/static/js/bundle.js:340345:86)
    at domToReact (http://localhost:3000/static/js/bundle.js:130001:36)
    at Object.replaceHtmlWithPdfSvg [as replace] (http://localhost:3000/static/js/bundle.js:340345:86)
    at domToReact (http://localhost:3000/static/js/bundle.js:130001:36)
    at HTMLReactParser (http://localhost:3000/static/js/bundle.js:130154:37)
    at webSvgToPdfSvg (http://localhost:3000/static/js/bundle.js:340525:71)

Reproduction

You can reproduce with the same code from the recharts docs.

const SomeComponent = () => (
    <ReactPDFChart>
        <BarChart width={730} height={250} data={data}>
            <CartesianGrid strokeDasharray="3 3" />
            <XAxis dataKey="name" />
            <YAxis />
            <Tooltip />
            <Legend />
            <Bar dataKey="pv" fill="#8884d8" />
            <Bar dataKey="uv" fill="#82ca9d" />
        </BarChart>

    </ReactPDFChart>
);

Validations

EvHaus commented 3 months ago

You'll need to remove the <Tooltip /> component. PDFs can't have tooltips.