New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add a BarChart and other type of Charts inside the pdf. #51
Comments
Hmm, interesting. I can reproduce when using client-side rendering. If you render on the server via I'll investigate to see what might be the problem. I don't have any ideas yet. Looks like this might be a bug with This seems to impact For now the only workaround I can offer is rendering the PDF via server-side (Node) APIs and not via |
You need to add isAnimationActive={false} when rendering bar component in the browser |
Great find @ganmor! That's exactly the problem! @Kartik0899 To fix your issue, you'll need to change: <BarChart data={data} width={500} height={300}>
<XAxis dataKey="name" />
<YAxis />
<CartesianGrid stroke="#ccc" strokeDasharray="3 3" />
<Bar dataKey="uv" fill="#8884d8" />
<Bar dataKey="pv" fill="#82ca9d" />
</BarChart> to <BarChart data={data} width={500} height={300}>
<XAxis dataKey="name" />
<YAxis />
<CartesianGrid stroke="#ccc" strokeDasharray="3 3" />
<Bar isAnimationActive={false} dataKey="uv" fill="#8884d8" />
<Bar isAnimationActive={false} dataKey="pv" fill="#82ca9d" />
</BarChart> I'm not sure there's anything |
🎉 This issue has been resolved in version 0.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@EvHaus I am facing an issue while displaying the BarChart inside my pdf.... So when I am using " import ReactPDFChart from "react-pdf-charts" " this and trying to get my BarChart then Barchart is only showing the CartesianGrid, XAxis and YAxis but no values.
Below is the code with "ReactPDFChart" -
import React from "react";
import ReactPDFChart from "react-pdf-charts";
import { BarChart, Bar, XAxis, YAxis, CartesianGrid } from "recharts";
const data = [
{ name: 'A', uv: 4000, pv: 2400, amt: 2400 },
{ name: 'B', uv: 3000, pv: 1398, amt: 2210 },
{ name: 'C', uv: 2000, pv: 9800, amt: 2290 },
{ name: 'D', uv: 2780, pv: 3908, amt: 2000 },
{ name: 'E', uv: 1890, pv: 4800, amt: 2181 },
{ name: 'F', uv: 2390, pv: 3800, amt: 2500 },
{ name: 'G', uv: 3490, pv: 4300, amt: 2100 },
];
// Silence useLayoutEffect does nothing on the server warnings. These come
// from recharts but they're harmless and just clutter the console output.
const consoleError = console.error;
console.error = function (message) {
if (message?.startsWith('Warning: useLayoutEffect does nothing on the server')) return;
consoleError.apply(console, arguments);
};
const PdfBarChart = () => (
<ReactPDFChart> <BarChart data={data} width={500} height={300}> <XAxis dataKey="name" /> <YAxis /> <CartesianGrid stroke="#ccc" strokeDasharray="3 3" /> <Bar dataKey="uv" fill="#8884d8" /> <Bar dataKey="pv" fill="#82ca9d" /> </BarChart> </ReactPDFChart>
);
export default PdfBarChart;
And when I try the same above code without "ReactPDFChart" it is giving me error like below -
htmlLayer.getElementsByClassName is not a function
TypeError: htmlLayer.getElementsByClassName is not a function
at CartesianAxis.componentDidMount (http://localhost:3000/static/js/bundle.js:144491:28)
So can anyone please guide or help me to figure this out and render the Bar and another Charts in the pdf.
The text was updated successfully, but these errors were encountered: