Line Chart

v0.2.2

Fully presentational line chart widget using Recharts. Supports multiple lines, custom styling, legends, tooltips, and responsive layouts.

View as Markdown

Install

npx shadcn@latest add @signalos/line-chart

Requires a configured @signalos registry and a valid SIGNALOS_REGISTRY_TOKEN - get access. Registry dependencies (@signalos/tokens, @signalos/chart-core) are pulled automatically.

Preview

Example & code

line-chart.example.tsx
import { LineChart } from "@/components/widgets/line-chart/LineChart"

const data = [
  { month: "Jan", revenue: 4000, expenses: 2400 },
  { month: "Feb", revenue: 3000, expenses: 1398 },
  { month: "Mar", revenue: 2000, expenses: 9800 },
  { month: "Apr", revenue: 2780, expenses: 3908 },
  { month: "May", revenue: 1890, expenses: 4800 },
  { month: "Jun", revenue: 2390, expenses: 3800 },
]

export default function LineChartExample() {
  return (
    <LineChart
      data={data}
      lines={[
        { dataKey: "revenue", name: "Revenue", stroke: "var(--chart-1)" },
        { dataKey: "expenses", name: "Expenses", stroke: "var(--chart-2)" },
      ]}
      xAxis={{ dataKey: "month" }}
      yAxis={{ tickFormatter: (value) => `$${value}` }}
      height={350}
    />
  )
}

Props

LineChartDataPoint

PropTypeDefaultDescription

LineChartLine

PropTypeDefaultDescription
dataKey*string-The data key to plot from your data points
namestring | undefined-Display name for the legend and tooltip
strokestring | undefined-Line color (use CSS custom property or hex)
strokeWidthnumber | undefined-Line thickness in pixels
strokeDasharraystring | undefined-Dash pattern (e.g., "5 5" for dashed line)
dotboolean | undefined-Whether to show dots on data points
animationDurationnumber | undefined-Whether to animate the line on mount

LineChartAxis

PropTypeDefaultDescription
dataKeystring | undefined-The data key for this axis
axisLineboolean | undefined-Whether to show the axis line
tickLineboolean | undefined-Whether to show tick marks
tickFormatter((value: unknown) => string) | undefined-Custom tick formatter function
labelstring | { value: string; angle?: number | undefined; position?: string | undefined; } | undefined-Label for the axis
hideboolean | undefined-Whether to hide the axis entirely
tickboolean | object | undefined-Axis tick styles

LineChartGrid

PropTypeDefaultDescription
horizontalboolean | undefined-Show horizontal grid lines
verticalboolean | undefined-Show vertical grid lines
strokestring | undefined-Grid line stroke color
strokeDasharraystring | undefined-Grid line stroke dash pattern

LineChartLegend

PropTypeDefaultDescription
verticalAlign"bottom" | "top" | "middle" | undefined-Legend position
align"left" | "center" | "right" | undefined-
layout"horizontal" | "vertical" | undefined-Legend layout
iconType"line" | "plainline" | "square" | "rect" | "circle" | "cross" | "diamond" | "star" | "triangle" | "wye" | undefined-Custom icon type
formatter((value: string) => ReactNode) | undefined-Custom legend formatter

LineChartTooltip

PropTypeDefaultDescription
labelFormatter((label: unknown) => ReactNode) | undefined-Custom tooltip formatter for label
formatter((value: ValueType, name: NameType, entry: Payload<ValueType, NameType>) => ReactNode) | undefined-Custom tooltip formatter for values
cursorboolean | object | undefined-Cursor style

LineChartProps

PropTypeDefaultDescription
data*LineChartDataPoint[]-Array of data points to plot
lines*LineChartLine[]-Array of line configurations
widthnumber | undefined-Chart width in pixels
heightnumber | undefined-Chart height in pixels
xAxisLineChartAxis | undefined-X-axis configuration
yAxisLineChartAxis | undefined-Y-axis configuration
gridboolean | LineChartGrid | undefined-Grid configuration
legendboolean | LineChartLegend | undefined-Legend configuration (false to hide)
tooltipboolean | LineChartTooltip | undefined-Tooltip configuration (false to hide)
margin{ top?: number | undefined; right?: number | undefined; bottom?: number | undefined; left?: number | undefined; } | undefined-Chart margin (top, right, bottom, left)
isLoadingboolean | undefined-Loading state
emptyStateReactNode-Empty state content
onDataPointClick((data: unknown, index: number) => void) | undefined-Click handler for line data points
responsiveboolean | undefined-Responsive container (auto-sizes to parent)
classNamestring | undefined-Container className
styleCSSProperties | undefined-Custom container styles

npm dependencies

recharts@^2.15.0

Changelog

Changelog - LineChart

0.2.2

  • Fix onDataPointClick's index argument always being 0 regardless of which point was clicked. Now derived from Recharts' activeTooltipIndex via chart-core's resolveChartClickIndex.

0.2.1

  • Update data-testid call sites for the renamed prop.

0.2.0

  • Factor shared colors, tooltip/legend config, skeleton, and empty state into the chart-core widget; public API unchanged.

0.1.1

  • Replaced any types with proper Recharts types (ValueType, NameType, Payload) in LineChartTooltip.formatter, labelFormatter, tickFormatter, and onDataPointClick.

0.1.0

Initial release.

  • Line chart component with Recharts integration
  • Support for multiple lines with custom colors and styling
  • Configurable axes, grid, legend, and tooltip
  • Responsive container support
  • Loading skeleton and empty state
  • Fully presentational (props-in/events-out pattern)