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

116 lines
1.9 KiB
TypeScript

"use client";
import React from "react";
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
LineElement,
Title,
Tooltip,
Legend,
} from "chart.js";
import { colors } from "@/lib/colors";
import { useTheme } from "next-themes";
import { hexToRGB } from "@/lib/utils";
import { Scatter } from "react-chartjs-2";
ChartJS.register(
CategoryScale,
LinearScale,
LineElement,
Title,
Tooltip,
Legend
);
const ScatterChart = ({ height = 350 }) => {
const { theme: mode } = useTheme();
const data: any = {
labels: [
"Eating",
"Drinking",
"Sleeping",
"Designing",
"Coding",
"Cycling",
"Running",
],
datasets: [
{
label: "Scatter Dataset",
data: [
{
x: -10,
y: 0,
},
{
x: 0,
y: 10,
},
{
x: 10,
y: 5,
},
{
x: 0.5,
y: 5.5,
},
],
backgroundColor: colors.warning,
},
],
scales: {
y: {
border: {
display: false
},
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"],
},
},
},
};
const options: any = {
responsive: true,
plugins: {
legend: {
labels: {
color: mode === 'light' ? colors["default-600"] : colors["default-300"],
},
},
},
maintainAspectRatio: false,
};
return (
<div>
<Scatter
options={options}
data={data}
height={height}
/>
</div>
);
};
export default ScatterChart;