1. Components
  2. Line Chart

Components

Line Chart

A line chart is a graphical representation that connects one or more series of data points with a continuous line.

   

Import LineChart

Tremor exports one component to create a line chart.

import { LineChart } from "@tremor/react";

Usage example

The example below shows a chart composition combining a Card with Title and LineChart components. Note: For the height, a number value has to b set (e.g, h-72, or h-[500px]. Keep in mind that h-full won't work.)

Population growth rate (1951 to 2021)

import { Card, Title, LineChart } from "@tremor/react";

const chartdata = [
  {
    year: 1951,
    "Population growth rate": 1.74,
  },
  {
    year: 1952,
    "Population growth rate": 1.93,
  },
  {
    year: 1953,
    "Population growth rate": 1.9,
  },
  {
    year: 1954,
    "Population growth rate": 1.98,
  },
  {
    year: 1955,
    "Population growth rate": 2,
  },
];

const dataFormatter = (number: number) =>
  `${Intl.NumberFormat("us").format(number).toString()}%`;

export default LineChart = () => (
  <Card>
    <Title>Population growth rate (1951 to 2021)</Title>
    <LineChart
      className="mt-6"
      data={chartdata}
      index="year"
      categories={["Population growth rate"]}
      colors={["blue"]}
      valueFormatter={dataFormatter}
      yAxisWidth={40}
    />
  </Card>
);

API Reference: LineChart

data
Description
The source data, in which each entry is a dictionary.
Type
any[]
Default
Values
categories
Description
Select the categories from your data. Used to populate the legend and toolip.
Type
string[]
Default
Values
E.g. ['Cat1', 'Cat2']
index
Description
Sets the key to map the data to the axis.
Type
string
Default
Values
colorsoptional
Description
Change the default colors. When using Typescript, import the Color type provided by tremor.
Type
Color[]
Default
Values
E.g. ['blue', 'indigo'].
valueFormatteroptional
Description
Controls the text formatting for the y-axis values. When using Typescript, import the ValueFormatter type provided by tremor.
Type
ValueFormatter
Default
Values
startEndOnlyoptional
Description
Show only the first and last elements in the x-axis. Great for smaller charts or sparklines.
Type
boolean
Default
false
Values
true, false
showXAxisoptional
Description
Controls the visibility of the X axis.
Type
boolean
Default
true
Values
true, false
showYAxisoptional
Description
Controls the visibility of the Y axis.
Type
boolean
Default
true
Values
true, false
yAxisWidthoptional
Description
Controls width of the vertical axis.
Type
number
Default
56
Values
showAnimationoptional
Description
Sets an animation to the chart when it is loaded.
Type
boolean
Default
true
Values
true, false
showTooltipoptional
Description
Controls the visibility of the tooltip.
Type
boolean
Default
true
Values
true, false
showLegendoptional
Description
Controls the visibility of the legend.
Type
boolean
Default
true
Values
true, false
showGridLinesoptional
Description
Controls the visibility of the gridlines within the plotted area.
Type
boolean
Default
true
Values
true, false
autoMinValueoptional
Description
Adjusts the minimum value in relation to the magnitude of the data.
Type
boolean
Default
false
Values
true, false
minValueoptional
Description
Sets the minimum value of the shown chart data.
Type
number
Default
Values
maxValueoptional
Description
Sets the maximum value of the shown chart data.
Type
number
Default
Values
curveTypeoptional
Description
Controls the type of the chart curve
Type
string
Default
linear
Values
basis, linear, step
connectNullsoptional
Description
Connects datapoints that have null values between them
Type
boolean
Default
false
Values
true, false