MDK Logo
UI Kitreact-devkitComponentsCoreCharts

LineChart

Customisable Chart.js line chart with built-in zoom, tooltip, and legend. Data is passed via props; the component does no fetching.

Customisable Chart.js line chart with built-in zoom, tooltip, and legend. Data is passed via props; the component does no fetching.

import { LineChart } from "@tetherto/mdk-react-devkit";
PropStatusTypeDefaultDescription
chartRefOptionalReact.MutableRefObject<IChartApi | null> | undefinedMutable ref to hold the LightWeightCharts reference
dataRequiredLineChartDataData of the chart
yTicksFormatterOptional((value: number) => string) | undefinedCallback to format ticks on y axis. If `priceFormatter` is given. It would be used instead.
customLabelOptionalstring | undefinedTODO: Doc
priceFormatterOptional((value: number) => string) | undefinedCallback to format ticks on y axis.
roundPrecisionOptionalnumber | undefinedThe number of decimals to show
timelineOptionalstring | undefinedTODO: DOC
fixedTimezoneOptionalstring | undefinedApplies offset if provided, otherwise timestamps are assumed to already be in local time. Otherwise, use browser's current timezone offset for consistent time display
shouldResetZoomOptionalboolean | undefinedWether to Reset Zoom
skipRoundOptionalboolean | undefinedPrevent rounding of values
skipMinWidthOptionalboolean | undefinedDo not enforce a min width
fadedBackgroundOptionalboolean | undefinedUse a faded background
backgroundColorOptionalstring | undefinedBackground color of the chart
customDateFormatOptionalstring | undefinedCustom date format
verticalLineLabelVisibleOptionalboolean | undefinedShow vertical line at mouse position
horizontalLineLabelVisibleOptionalboolean | undefinedShow horizontal line at mouse position
showDateInTooltipOptionalboolean | undefinedShow date line in tooltip
disableAutoRangeOptionalboolean | undefinedDisable automatically determining range
uniformDistributionOptionalboolean | undefinedChanges horizontal scale marks generation. With this flag equal to true, marks of the same weight are either all drawn or none are drawn at all.
unitOptionalstring | undefinedThe unit to display with values
beginAtZeroOptionalboolean | undefinedStarts the value axis at 0
showPointMarkersOptionalboolean | undefinedShow a marker on the line
heightOptionalnumber | undefinedControls the height of the chart. Default: 240

Usage

Time-series line chart built on lightweight-charts. Supports multi-series data, custom tooltips, vertical / horizontal crosshair labels, manual zoom, point markers, fixed-timezone formatting, and auto-scaling.

For most use cases prefer wrapping in ChartContainer or LineChartCard so you get title, legend, range selector, and loading / empty states for free.

Key props

PropTypeRequiredDefaultDescription
dataLineChartDatayes{ datasets: LineDataset[] }.
chartRefMutableRefObject<IChartApi | null>noHold the underlying chart API.
yTicksFormatter(value: number) => stringnoY-axis tick formatter.
priceFormatter(value: number) => stringnoTake-precedence formatter.
timelinestringnoCurrent timeline (drives auto-fit).
fixedTimezonestringnoIANA timezone (applies offset).
unitstringno""Unit appended in tooltips.
heightnumberno240Pixel height.

See types.ts for the full prop set (20+ props).

Data contracts

type LineDataPoint = { x: number; y: number | null | undefined };
type LineDataset = {
  label?: string;
  visible?: boolean;
  borderColor: string;
  borderWidth?: number;
  data: LineDataPoint[];
};
type LineChartData = { datasets: LineDataset[] };

Example

/** * Runnable example for LineChart. */import { LineChart } from '@tetherto/mdk-react-devkit'const NOW = Date.now()const MIN = 60 * 1000const points = Array.from({ length: 90 }, (_, i) => ({  x: NOW - (90 - i) * MIN,  y: 50 + Math.sin(i / 8) * 6 + Math.random() * 1.2,}))const data = {  datasets: [    {      label: 'Hashrate',      borderColor: '#4f9ef5',      borderWidth: 2,      data: points,    },  ],}export const LineChartExample = () => {  return <LineChart data={data} height={320} unit="TH/s" />}