UNPKG

@etsoo/materialui

Version:

TypeScript Material-UI Implementation

54 lines (53 loc) 1.9 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from "react"; import LinearProgress from "@mui/material/LinearProgress"; /** * Line chart * @param props Props * @returns Component */ export function LineChart(props) { // Destruct const { data, options, subtitle, title } = props; // State const [LineType, setLineType] = React.useState(); React.useEffect(() => { Promise.all([ import("react-chartjs-2"), import("chart.js"), import("chartjs-plugin-datalabels") ]).then(([{ Line }, { Chart: ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend }, ChartDataLabels]) => { // https://www.chartjs.org/docs/latest/getting-started/ ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend, ChartDataLabels // CommonJS says 'id' is missing ); setLineType(Line); }); }, []); return LineType == null ? (_jsx(LinearProgress, {})) : (_jsx(LineType, { options: { scales: { x: { ticks: { display: false //this will remove only the label } } }, responsive: true, plugins: { datalabels: { display: (context) => context.dataset.data.length <= 31, align: "end" }, legend: { position: "top" }, subtitle: subtitle ? { text: subtitle, display: true } : undefined, title: title ? { text: title, display: true } : undefined }, ...options }, data: data })); }