Skip to content

Commit 3466ac9

Browse files
committed
Scope chartjs-plugin-datalabels to WeatherChart only
Registering the plugin globally on ChartJS attached it to every chart instance in the app, including the sensor history chart, which then drew labels on top of every data point. Pass the plugin via the per-instance 'plugins' prop on the WeatherChart's <Chart> instead so unrelated charts remain unaffected.
1 parent 22f4af3 commit 3466ac9

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎frontend/src/components/WeatherChart.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ChartJS.register(
2424
PointElement,
2525
LineElement,
2626
LineController,
27-
ChartDataLabels,
2827
);
2928

3029
type WeatherChartData = {
@@ -121,7 +120,8 @@ const WeatherChart: React.FC<WeatherChartProps> = ({
121120
plugins: {
122121
legend: { display: false },
123122
tooltip: { enabled: false },
124-
// Disabled by default — re-enabled per-dataset (PV bars only).
123+
// Plugin scoped to this chart via the `plugins` prop on <Chart>.
124+
// Disabled at chart level — re-enabled per-dataset on PV bars only.
125125
datalabels: { display: false },
126126
},
127127
scales: {
@@ -167,7 +167,14 @@ const WeatherChart: React.FC<WeatherChartProps> = ({
167167
},
168168
};
169169

170-
return <Chart type="bar" options={options} data={chartData}></Chart>;
170+
return (
171+
<Chart
172+
type="bar"
173+
options={options}
174+
data={chartData}
175+
plugins={[ChartDataLabels]}
176+
/>
177+
);
171178
};
172179

173180
export default WeatherChart;

0 commit comments

Comments
 (0)