import { createAreaChart } from 'carbon-uplot';
let showPoints = true;
let chart = buildChart(showPoints);
button.addEventListener('click', () => {
showPoints = !showPoints;
chart.destroy();
chart = buildChart(showPoints);
});
function buildChart(show) {
return createAreaChart(el, {
data: [timestamps, cpuSeriesA, cpuSeriesB, cpuSeriesC],
yRange: [0, 100],
series: [
{ label: 'prod-vsi-01', points: { show } },
{ label: 'prod-vsi-02', points: { show } },
{ label: 'prod-vsi-03', points: { show } },
],
});
}
import 'carbon-uplot/web-components';
// <cu-area-chart></cu-area-chart>
let showPoints = true;
el.data = [timestamps, cpuSeriesA, cpuSeriesB, cpuSeriesC];
el.yRange = [0, 100];
el.series = buildSeries(showPoints);
button.addEventListener('click', () => {
showPoints = !showPoints;
el.series = buildSeries(showPoints);
});
function buildSeries(show) {
return [
{ label: 'prod-vsi-01', points: { show } },
{ label: 'prod-vsi-02', points: { show } },
{ label: 'prod-vsi-03', points: { show } },
];
}
import { useState, useMemo } from 'react';
import { AreaChart } from 'carbon-uplot/react';
// React 19+ users can use the Custom Element API directly.
function TogglePoints() {
const [showPoints, setShowPoints] = useState(true);
const series = useMemo(
() => [
{ label: 'prod-vsi-01', points: { show: showPoints } },
{ label: 'prod-vsi-02', points: { show: showPoints } },
{ label: 'prod-vsi-03', points: { show: showPoints } },
],
[showPoints],
);
return (
<>
<button onClick={() => setShowPoints((p) => !p)}>Toggle points</button>
<AreaChart
data={[timestamps, cpuSeriesA, cpuSeriesB, cpuSeriesC]}
yRange={[0, 100]}
series={series}
/>
</>
);
}