[bug]: Cannot render chart
Describe the bug
I copied exactly the same code form shadcn charts example. But I can't see any chart in my app.
Here is my code:
"use client";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@ui/components/ui/card";
import {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
type ChartConfig,
} from "@ui/components/ui/chart";
import { TrendingUp } from "lucide-react";
import { CartesianGrid, LabelList, Line, LineChart, XAxis } from "recharts";
export const description = "A line chart with a label";
const chartData = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
{ month: "April", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "June", desktop: 214, mobile: 140 },
];
const chartConfig = {
desktop: {
label: "Desktop",
color: "#2563eb",
},
mobile: {
label: "Mobile",
color: "#60a5fa",
},
} satisfies ChartConfig;
const ProgressChart = () => {
return (
<Card>
<CardHeader>
<CardTitle>Line Chart - Label</CardTitle>
<CardDescription>January - June 2024</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
<LineChart
accessibilityLayer
data={chartData}
margin={{
top: 20,
left: 12,
right: 12,
}}
>
<CartesianGrid vertical={false} />
<XAxis
dataKey="month"
tickLine={false}
axisLine={false}
tickMargin={8}
tickFormatter={(value) => value.slice(0, 3)}
/>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent indicator="line" />}
/>
<Line
dataKey="desktop"
type="natural"
stroke="var(--color-desktop)"
strokeWidth={2}
dot={{
fill: "var(--color-desktop)",
}}
activeDot={{
r: 6,
}}
>
<LabelList
position="top"
offset={12}
className="fill-foreground"
fontSize={12}
/>
</Line>
</LineChart>
</ChartContainer>
</CardContent>
<CardFooter className="flex-col items-start gap-2 text-sm">
<div className="flex gap-2 font-medium leading-none">
Trending up by 5.2% this month <TrendingUp className="h-4 w-4" />
</div>
<div className="text-muted-foreground leading-none">
Showing total visitors for the last 6 months
</div>
</CardFooter>
</Card>
);
};
export default ProgressChart;
Here is my output.
Affected component/components
Charts
How to reproduce
"use client";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@ui/components/ui/card";
import {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
type ChartConfig,
} from "@ui/components/ui/chart";
import { TrendingUp } from "lucide-react";
import { CartesianGrid, LabelList, Line, LineChart, XAxis } from "recharts";
export const description = "A line chart with a label";
const chartData = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
{ month: "April", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "June", desktop: 214, mobile: 140 },
];
const chartConfig = {
desktop: {
label: "Desktop",
color: "#2563eb",
},
mobile: {
label: "Mobile",
color: "#60a5fa",
},
} satisfies ChartConfig;
const ProgressChart = () => {
return (
<Card>
<CardHeader>
<CardTitle>Line Chart - Label</CardTitle>
<CardDescription>January - June 2024</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
<LineChart
accessibilityLayer
data={chartData}
margin={{
top: 20,
left: 12,
right: 12,
}}
>
<CartesianGrid vertical={false} />
<XAxis
dataKey="month"
tickLine={false}
axisLine={false}
tickMargin={8}
tickFormatter={(value) => value.slice(0, 3)}
/>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent indicator="line" />}
/>
<Line
dataKey="desktop"
type="natural"
stroke="var(--color-desktop)"
strokeWidth={2}
dot={{
fill: "var(--color-desktop)",
}}
activeDot={{
r: 6,
}}
>
<LabelList
position="top"
offset={12}
className="fill-foreground"
fontSize={12}
/>
</Line>
</LineChart>
</ChartContainer>
</CardContent>
<CardFooter className="flex-col items-start gap-2 text-sm">
<div className="flex gap-2 font-medium leading-none">
Trending up by 5.2% this month <TrendingUp className="h-4 w-4" />
</div>
<div className="text-muted-foreground leading-none">
Showing total visitors for the last 6 months
</div>
</CardFooter>
</Card>
);
};
export default ProgressChart;
Codesandbox/StackBlitz link
No response
Logs
No response
System Info
- Ubuntu 24.04.1 LTS
- Chrome Browser
Before submitting
- [X] I've made research efforts and searched the documentation
- [X] I've searched for existing issues
Did you install the necessary packages? Also, do you maybe get an error in the console?
Did you install the necessary packages? Also, do you maybe get an error in the console?
Yes I installed all packages. And also I did not get any error in console.
same issue here, updating recharts to alpha 4 as suggested in doc dont solve my issue
Using NextJS 15 RC with PPR? That might cause this.
@younes101020 @ikraamdaanis
Adding width and height to chart type fixed the problem for me.
<LineChart accessibilityLayer data={chartData} margin={{ top: 20, left: 12, right: 12, }} width={500} height={300} >
@iFlyinq Yes, but that was not related to ppr, overrides field was on root level instead of being nested to my package manager name (pnpm)
"dependencies": {
"next": "15.0.0-canary.152",
"react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "19.0.0-rc-7771d3a7-20240827",
"react-is": "19.0.0-rc-7771d3a7-20240827",
"recharts": "2.13.0-alpha.5",
}
"pnpm": {
"overrides": {
"react-is": "$react-is"
}
}
hope this can help
Also having issues, using next + react canaries, have to add sizes to LineChart instead of container, but then lose the full width stuff
@JClackett make sure to overrides react-is package with your react version and use alpha versions for rechart like 2.13.0-alpha.5, i had the same issue as you
FWIW: Next.15 does not require manual install of sharp. I only found this out after setting up and the charts not rendering. I removed sharp and everything runs as expected.
@iFlyinq Yes, but that was not related to ppr,
overridesfield was on root level instead of being nested to my package manager name (pnpm)"dependencies": { "next": "15.0.0-canary.152", "react": "19.0.0-rc-7771d3a7-20240827", "react-dom": "19.0.0-rc-7771d3a7-20240827", "react-is": "19.0.0-rc-7771d3a7-20240827", "recharts": "2.13.0-alpha.5", } "pnpm": { "overrides": { "react-is": "$react-is" } }hope this can help
Thanks, this workaround works for me too, just updated the RC version to 19.0.0-rc-69d4b800-20241021