LineChart

Feature-rich line chart with dual Y-axis support, multiple curve types, area fills, and interactive legends. Perfect for time series data, metrics dashboards, and analytics.

Playground

Click the legend badges to toggle series visibility. Hover over the chart to see interpolated values. Try different curve types and settings below.

Props

Midnight
OffOn
OffOn
Code
<LineChart
  data={data}
  theme="midnight"
  curve="linear"
/>

Basic Usage

Import the component and configure your series:

tsx
import { LineChart } from '@derpdaderp/chartkit';

const data = [
  { time: '09:00', p50: 1.5, p95: 2.1, p99: 3.2 },
  { time: '10:00', p50: 1.8, p95: 2.4, p99: 3.8 },
  { time: '11:00', p50: 1.6, p95: 2.2, p99: 3.5 },
  // ...more data points
];

const series = [
  { key: 'p50', label: 'p50', displayValue: '1.8 ms' },
  { key: 'p95', label: 'p95', displayValue: '2.3 ms' },
  { key: 'p99', label: 'p99', displayValue: '3.5 ms' },
];

<LineChart
  data={data}
  series={series}
  theme="midnight"
  unit="ms"
/>

Single Series (Simplified API)

For single-series charts, use dataKey and label instead of the series array:

tsx
<LineChart
  data={data}
  dataKey="value"
  label="Revenue"
  theme="midnight"
  unit="$"
  responsive
/>

Curve Types

Choose from 5 interpolation methods with the curve prop:

curve="linear"
0.0 ms1.0 ms2.1 ms09:0012:0015:00
curve="monotone"
0.0 ms1.0 ms2.1 ms09:0012:0015:00
curve="step"
0.0 ms1.0 ms2.1 ms09:0012:0015:00
curve="stepAfter"
0.0 ms1.0 ms2.1 ms09:0012:0015:00
tsx
// Smooth curves (Catmull-Rom spline)
<LineChart data={data} series={series} theme="midnight" curve="monotone" />

// Step function (horizontal then vertical)
<LineChart data={data} series={series} theme="midnight" curve="step" />

Dual Y-Axis

Display series with different scales using yAxisLeft, yAxisRight, and yAxisId per series:

0.0 req/s858.3 req/s1.7K req/s0.0 ms50.3 ms100.7 ms00:0012:0023:00
tsx
<LineChart
  data={data}
  series={[
    { key: 'requests', label: 'Requests', yAxisId: 'left' },
    { key: 'latency', label: 'Latency', yAxisId: 'right', strokeDasharray: '5,5' },
  ]}
  yAxisLeft={{ unit: 'req/s' }}
  yAxisRight={{ unit: 'ms' }}
  theme="midnight"
  curve="monotone"
/>

Area Chart

Create beautiful area charts by adding area: true to your series. The gradient automatically fades from the line color to transparent.

0.0 $1.0 $2.1 $09:0012:0018:00
tsx
// Simple area chart
<LineChart
  data={data}
  series={[{ key: 'value', label: 'Revenue', area: true }]}
  theme="midnight"
  curve="monotone"
  unit="$"
/>

Customizing Area Opacity

Control the gradient intensity with areaOpacity (default: 0.4 at top, fading to 0.05 at bottom):

0.0 ms1.6 ms3.2 ms09:0012:0018:00
tsx
// Multiple areas with different opacities
<LineChart
  data={data}
  series={[
    { key: 'p50', label: 'p50', area: true, areaOpacity: 0.2 },
    { key: 'p95', label: 'p95', area: true, areaOpacity: 0.6 },
  ]}
  theme="midnight"
  curve="monotone"
/>

Data Point Dots

Show dots on data points with showDots:

0.0 ms1.0 ms2.1 ms09:0009:0012:00
tsx
<LineChart
  data={data}
  series={[{ key: 'value', label: 'Value' }]}
  theme="midnight"
  showDots
  dotsOnHover={false}  // Always show dots (not just on hover)
  dotSize={4}
/>

Glow Effect

Enable the glow effect for a more dramatic look:

0.0 ms2.4 ms4.8 ms09:0018:0006:00

Custom Series Styling

Override colors and stroke styles per series:

tsx
<LineChart
  data={data}
  series={[
    { key: 'actual', label: 'Actual', color: '#22c55e', strokeWidth: 2 },
    { key: 'target', label: 'Target', color: '#f59e0b', strokeDasharray: '8,4' },
    { key: 'forecast', label: 'Forecast', color: '#6b7280', strokeDasharray: '2,2' },
  ]}
  theme="midnight"
  curve="monotone"
/>

Responsive Width

Use the responsive prop to automatically fill the container width:

tsx
<LineChart
  data={data}
  series={series}
  theme="midnight"
  responsive
  height={300}
/>

Props

PropTypeDefaultDescription
data*T[]-Data array with time and series values
seriesSeriesConfig[]-Series configuration (optional if using dataKey)
dataKeykeyof T-Single series data key (simplified API)
labelstring-Label for single series (used with dataKey)
widthnumber600Chart width (ignored if responsive=true)
heightnumber260Chart height in pixels
responsivebooleanfalseAuto-fill container width
theme*ThemeName-Theme name
timeKeykeyof T"time"Key for time/x-axis values
unitstring""Unit label for left Y-axis (shorthand)
yAxisLeftYAxisConfig-Left Y-axis configuration
yAxisRightYAxisConfig-Right Y-axis configuration (enables dual-axis)
curveCurveType"linear"Line interpolation: linear, monotone, step, stepBefore, stepAfter
showDotsbooleanfalseShow dots on data points
dotSizenumber3Dot radius in pixels
dotsOnHoverbooleantrueShow dots only on hover
glowbooleanfalseEnable glow effect on lines
gridGridOptions | booleantrueGrid line configuration
areaGradientAreaGradientOptions-Customize area gradient: { from, to, direction }
showLegendbooleantrueShow/hide legend
annotationsAnnotation[]-Reference lines and areas
connectNullsbooleantrueConnect lines through null values
onDataPointClickfunction-Click handler for data points
renderTooltipfunction-Custom tooltip renderer
classNamestring-Additional CSS class
styleCSSProperties-Custom styles for container

SeriesConfig

Each series is configured with the following properties:

PropTypeDefaultDescription
key*string-Unique key matching data property
label*string-Display label
displayValuestring-Current/summary value shown in legend badge
yAxisId'left' | 'right''left'Y-axis assignment for dual-axis charts
areabooleanfalseFill area under the line (gradient fill)
areaOpacitynumber0.4Area gradient start opacity (fades to 0.05)
colorstring-Custom line color (overrides theme)
strokeDasharraystring-Dash pattern (e.g., "5,5")
strokeWidthnumber2Line stroke width

YAxisConfig

Configure Y-axis behavior:

PropTypeDefaultDescription
unitstring-Unit label (e.g., "ms", "req/s", "%")
minnumber-Minimum value (auto-calculated if not set)
maxnumber-Maximum value (auto-calculated if not set)
tickCountnumber3Number of ticks
format(value: number) => string-Custom tick label formatter

Migration from MonitorLine

MonitorLine has been renamed to LineChart. The API is backward compatible, just update your imports:

tsx
// Before
import { MonitorLine } from '@derpdaderp/chartkit';

// After
import { LineChart } from '@derpdaderp/chartkit';

// MonitorLine is still exported as a deprecated alias