Line Chart

A flexible and composable line chart built with D3.js and styled using Tailwind.

Example

Series 1
Series 2

Installation

./components/charts/LineChart.tsx

How It Works

This chart uses a compound component pattern to provide maximum flexibility and composability. The chart is built using d3.scaleLinear for both axes and d3.line to draw the SVG paths.

The main components are:

  • LineChart.Container - The main container that provides context for all child components
  • LineChart.Line - Renders a single line series with data points
  • LineChart.XAxis - Renders the X axis
  • LineChart.YAxis - Renders the Y axis

Each line series can have its own color and label, which automatically updates the legend. The chart automatically scales based on the combined data range of all series.