Skip to main content

Line Chart

The LineChart component is a flexible line chart built with recharts. It supports multiple series, customizable dots, labels, tooltips, legends, Cartesian grid, and tick formatting.

import { LineChart } from "tawuniya/components";

👉 View in Storybook

Props​

PropTypeDefaultDescription
dataT[]-Array of data objects.
seriesChartConfig-Defines each line series with color, name, etc.
typeCurveType"natural"Line curve type (linear, monotoneX, natural, etc.)
dataKeyTypedDataKey<T, unknown>-Key used for X-axis.
showCursorbooleanfalseShow cursor line on hover.
hideXAxisbooleanfalseHide X-axis.
hideYAxisbooleanfalseHide Y-axis.
hideTooltipLabelbooleanfalseHide label in tooltip.
showTickLinebooleanfalseShow tick lines on axes.
showAxisLinebooleanfalseShow axis lines.
showCartesianGridbooleanfalseShow grid lines.
showLegendbooleanfalseShow legend.
tickMarginnumber8Margin between tick labels and axes.
marginPartial<Margin>{ top: 20, left: 12, right: 12 }Chart margin.
strokeWidthnumber2Width of the line stroke.
dotDotConfig{ show: false, fill: "var(--color-background)", strokeWidth: 2, activeRadius: 6 }Dot configuration for data points.
labelListLabelListConfig{ show: false, position: "top", offset: 12, fontSize: 12, fontWeight: "regular" }Configuration for line labels.
classNamestring-Custom class for chart container.
tickFormatter(value: unknown) => string-Custom function to format axis tick values.
wrapperClassNamestring-Custom class for the outer wrapper.

Usage​

Basic Example​

const data = [
{ month: "Jan", mobile: 40, desktop: 30 },
{ month: "Feb", mobile: 35, desktop: 45 },
];

const series = {
mobile: { color: "var(--color-primary)", name: "Mobile" },
desktop: { color: "var(--color-success)", name: "Desktop" },
};

<LineChart data={data} series={series} dataKey="month" />;

With Dots​

<LineChart
data={data}
series={series}
dataKey="month"
dot={{ show: true, fill: "#fff", strokeWidth: 3, activeRadius: 8 }}
/>;

With Labels​

<LineChart
data={data}
series={series}
dataKey="month"
labelList={{ show: true, position: "top", fontSize: 12, fontWeight: "semibold" }}
/>;

With Cartesian Grid and Legend​

<LineChart
data={data}
series={series}
dataKey="month"
showCartesianGrid
showLegend
/>;

Custom Tick Formatter​

<LineChart
data={data}
series={series}
dataKey="month"
tickFormatter={(val) => `$${val}`}
/>;

Multiple Series​

<LineChart
data={data}
series={{
mobile: { color: "var(--color-primary)", name: "Mobile" },
desktop: { color: "var(--color-success)", name: "Desktop" },
}}
dataKey="month"
/>;

Features​

  • Supports multiple series with different colors.
  • Customizable dots and active dots.
  • Supports curve types (linear, natural, monotoneX, etc.).
  • Optional Cartesian grid, legend, and tooltip.
  • Customizable labels with font size, weight, style, and position.
  • Axis tick formatting.

Notes​

  • dot and labelList can be combined for enhanced data visualization.
  • series order determines line rendering order.
  • Tooltip labels can be hidden individually using hideTooltipLabel.