mediahub-fe/app/[locale]/(protected)/charts/chart-js/charts-chartjs-area/basic-area.tsx

96 lines
1.6 KiB
TypeScript

"use client";
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
LineElement,
Title,
Tooltip,
Legend,
PointElement,
} from "chart.js";
import { colors } from "@/lib/colors";
import { useTheme } from "next-themes";
import { hexToRGB } from "@/lib/utils";
import { Line } from "react-chartjs-2";
ChartJS.register(
CategoryScale,
LinearScale,
LineElement,
Title,
Tooltip,
Legend,
PointElement
);
const BasicArea = ({ height = 350 }) => {
const { theme: mode } = useTheme();
const data: any = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
fill: true,
label: "Dataset",
data: [-20, -60, 35, 59, 80, -50, 81, 56, 55, 40],
borderColor: hexToRGB(colors.warning, 1),
},
],
};
const options: any = {
responsive: true,
plugins: {
filler: {
propagate: false,
},
legend: {
labels: {
color: mode === 'light' ? colors["default-600"] : colors["default-300"],
},
},
},
scales: {
y: {
grid: {
drawTicks: false,
display: false,
},
ticks: {
color: mode === 'light' ? colors["default-600"] : colors["default-300"],
},
},
x: {
grid: {
drawTicks: false,
display: false,
},
ticks: {
color: mode === 'light' ? colors["default-600"] : colors["default-300"]
}
}
},
maintainAspectRatio: false,
};
return (
<div>
<Line options={options} data={data} height={height} />
</div>
);
};
export default BasicArea;