AI
Charts logov1.0.0

LineChart

LineChart visualizes continuous data sequences, dynamic rates, and time-series fluctuations with precision Bézier curves, active marker points, and interactive crosshair scrubbing.

typescript
// Framework-Agnostic Core
import { Chart, downsampleLTTB } from '@nofinite/charts';

// React Adapter
import { LineChart } from '@nofinite/charts/react';

Interactive Preview

Loading preview...

1. Framework-Agnostic Core Usage

Direct DOM Mounting (new Chart)

Mount an interactive line chart directly to any HTML DOM node:

typescript
import { Chart } from '@nofinite/charts';
import '@nofinite/nuicss/styles.css';

const container = document.querySelector('#cpu-trend-chart');

const chart = new Chart({
  element: container,
  variant: 'line',
  data: [
    { time: '00:00', cpu: 22 },
    { time: '04:00', cpu: 35 },
    { time: '08:00', cpu: 68 },
    { time: '12:00', cpu: 84 },
    { time: '16:00', cpu: 52 },
    { time: '20:00', cpu: 40 }
  ],
  xAccessor: (d) => d.time,
  yAccessor: (d) => d.cpu,
  color: 'var(--color-primary)',
  showGrid: true,
  showAxes: true,
  showTooltip: true,
  showCrosshair: true
});

// Real-time telemetry tick update
chart.update([
  { time: '00:00', cpu: 22 },
  { time: '04:00', cpu: 35 },
  { time: '08:00', cpu: 68 },
  { time: '12:00', cpu: 84 },
  { time: '16:00', cpu: 52 },
  { time: '20:00', cpu: 40 },
  { time: '24:00', cpu: 38 }
]);

// Cleanup
chart.destroy();

High-Density Time-Series Downsampling (downsampleLTTB)

When monitoring 10,000 to 1,000,000 telemetry points, use the built-in Largest Triangle Three Buckets (LTTB) algorithm to preserve visual peaks and troughs while keeping SVG frame rates at 60 FPS:

typescript
import { downsampleLTTB, Chart } from '@nofinite/charts';

const rawHighFrequencyData = [
  // 50,000 high-frequency sensor ticks
];

// Downsample 50,000 points to 600 visually identical points
const optimizedData = downsampleLTTB(rawHighFrequencyData, 600);

const chart = new Chart({
  element: document.querySelector('#telemetry-chart'),
  variant: 'line',
  data: optimizedData
});

2. React Adapter Usage

Declarative React JSX component for React 18 & 19:

tsx
import { LineChart } from '@nofinite/charts/react';

const serverLoad = [
  { time: '00:00', cpu: 22 },
  { time: '04:00', cpu: 35 },
  { time: '08:00', cpu: 68 },
  { time: '12:00', cpu: 84 },
  { time: '16:00', cpu: 52 },
  { time: '20:00', cpu: 40 }
];

export default function CpuLoadChart() {
  return (
    <div className="w-full h-64 p-4 border border-default rounded-xl bg-surface">
      <LineChart
        data={serverLoad}
        xAccessor={(d) => d.time}
        yAccessor={(d) => d.cpu}
        strokeColor="var(--color-primary)"
        showTooltip={true}
        showCrosshair={true}
      />
    </div>
  );
}

API Reference

Framework-Agnostic Core Options (ChartOptions)

OptionTypeDefaultDescription
elementHTMLElement—Target DOM container to mount into.
variant'line''line'Specifies continuous line visualization engine.
dataDataPoint[][]Array of continuous sequence data objects.
xAccessor(d: any) => anyd => d.xExtracts sequential X key or timestamp.
yAccessor(d: any) => numberd => d.yExtracts numeric trend value.
colorstring'var(--color-primary)'Line stroke color or token variable.
heightnumber260Height in pixels.
showCrosshairbooleantrueRenders dual-axis interactive scrubbing lines.
showTooltipbooleantrueRenders glassmorphic hover popover.

React Component Props

PropTypeDefaultDescription
dataT[]——
seriesChartSeries<T>[]——
referenceLinesReferenceLine[]——
showLegendboolean——
legendPositionenumbottom—
xAccessor((d: T) => string | number | Date)——
yAccessor((d: T) => number)——
widthnumber——
heightnumber300—
margin{ top: number; right: number; bottom: number; left: number; }——
colorstringvar(--chart-1, var(--color-primary))—
classNamestring——
ariaLabelstring——
showGridbooleantrue—
showAxesbooleantrue—
showTooltipbooleantrue—
showCrosshairbooleantrue—
animatebooleantrue—
downsampleThresholdnumber——
xTickFormat((val: string | number | Date) => string)——
yTickFormat((val: number) => string)——
tooltipFormatterany——
onToggleSeries((seriesName: string) => void)——