Linechart Examples

Up, down, all around.

<LineChart />

There are loads of ways to use the <LineChart /> component.

Basic Usage

export const MyApp = () => {
  return (
    <>
      <h2>My Chart</h2>
      <LineChart data={[50, 100, 30]} />
    </>
  );
};
BarChartLine Chart

Let's add some labels:

<LineChart
  data={[50, 100, 30]}
  labels={['1st', '2nd', '3rd']} 
/>
BarChartLine Chart1st

And make the line reach the edges of the chart:

<LineChart
  data={[50, 100, 30]}
  labels={['1st', '2nd', '3rd']}
  fullWidthLine={true} 
/>
BarChartLine Chart1st

And let's make the output SVG smaller - half the default height & width:

<LineChart
  data={[50, 100, 30]}
  labels={['1st', '2nd', '3rd']}
  fullWidthLine={true}
  height={150} 
  width={150} 
/>
BarChartLine Chart1st

Built In Styling

There's a bunch of built-in options for styling the charts!

Color

The colors parameter allows coloring of line elements with corresponding indexes.

<LineChart
  data={[50, 100, 30]}
  labels={['1st', '2nd', '3rd']}
  colors="cyan"
/>
BarChartLine Chart1st

Colors will wrap if there are more lines than colors, which makes alternating colors trivial!

<LineChart
  data={[
    [50, 100, 30, 10],
    [10, 30, 100, 50],
    [75, 25, 90, 40],
  ]}
  labels={['1st', '2nd', '3rd', '4th']}
  colors={["cyan", "magenta"]} 
/>
BarChartLine Chart3rd

Stroke

Of course the line stroke can also be customized via thickness, cap, and lineType:

<LineChart
  data={[50, 100, 30, 10]}
  labels={['1st', '2nd', '3rd', '4th']}
  colors="cyan"
  thickness={10} 
  cap="round"
  lineType="smooth"
/>
BarChartLine Chart1st

Multiple line options can also be provided as arrays, with each value targeting the corresponding line:

<LineChart
  data={[
    [50, 100, 30, 10],
    [10, 30, 100, 50],
  ]}
  labels={['1st', '2nd', '3rd', '4th']}
  colors={["cyan", "magenta"]}
  thickness={[3, 10]} 
  lineType={["straight", "smooth"]} 
/>
BarChartLine Chart2nd

Gradients

Not only that but gradients are fully supported by default.

<LineChart
  data={[50, 100, 30, 10]}
  labels={['1st', '2nd', '3rd', '4th']}
  thickness={10}
  lineType="smooth"
  gradientColors={[ 
    'oklch(0.7017 0.3225 328.36)', 
    'oklch(0.9054 0.15455 194.769)', 
  ]} 
  gradientDirection={'left-to-right'} 
/>
BarChartLine Chart1st

You can also change the stops for colors by supplying a percentage along with each color in the format color:% like so:

<LineChart
  data={[50, 100, 30, 10]}
  labels={['1st', '2nd', '3rd', '4th']}
  thickness={10}
  lineType="smooth"
  gradientColors={[
    'gray:33%', 
    'yellow:33%', 
    'yellow:66%', 
    'gray:66%', 
    'gray:100%', 
  ]}
  gradientDirection={'left-to-right'}
/>
BarChartLine Chart1st

I've also added support for instead having a continuous shared gradient!

<LineChart
  data={[
    [50, 100, 30, 10],
    [10, 30, 100, 50],
  ]}
  labels={['1st', '2nd', '3rd', '4th']}
  thickness={[3, 10]}
  lineType={["straight", "smooth"]}
  gradientColors={[
    'oklch(0.7017 0.3225 328.36)',
    'oklch(0.9054 0.15455 194.769)',
  ]}
  gradientDirection={'left-to-right'}
  gradientMode="continuous"
/>
BarChartLine Chart2nd

On this page