Skip to content

Commit

Permalink
Fix Chart flickering on load
Browse files Browse the repository at this point in the history
  • Loading branch information
Ru Chern Chong committed Nov 14, 2023
1 parent b8b66d5 commit 4741c10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 2 additions & 6 deletions components/Infographic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ type InfographicProps = {
electricCars: Car[];
};

const DynamicLineChart = dynamic(() => import("../components/LineChart"), {
loading: () => <p>Loading...</p>,
});
const DynamicLineChart = dynamic(() => import("../components/LineChart"));

export const Infographic = ({ electricCars }: InfographicProps) => {
const initialDatasets: ChartDataset[] = transformDataToDatasets(
Expand All @@ -39,10 +37,8 @@ export const Infographic = ({ electricCars }: InfographicProps) => {
mode: "index",
},
plugins: {
legend: {
display: false,
},
tooltip: {
itemSort: (a, b) => (b.raw as number) - (a.raw as number),
callbacks: {
footer: (tooltipItems) => {
let sum = 0;
Expand Down
8 changes: 7 additions & 1 deletion components/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ type LineChartProps = {
};

export const LineChart = ({ data, options }: LineChartProps) => {
return <Line data={data} options={options} className="bg-neutral-50 p-4" />;
return (
<Line
data={data}
options={options}
className="bg-neutral-50 p-2 md:aspect-video md:min-h-full"
/>
);
};

export default LineChart;

0 comments on commit 4741c10

Please sign in to comment.