--- title: LineChart description: "`LineChart` is a component for drawing line charts to compare multiple sets of data." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/chart/line-chart.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/chart - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-chart-linechart--basic --- ```tsx interface Data { date: string desktop: number mobile: number tablet: number } const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo( () => [ { date: "2026-03-01", desktop: faker.number.int({ max: 5000, min: 1000 }), mobile: faker.number.int({ max: 5000, min: 1000 }), tablet: faker.number.int({ max: 5000, min: 1000 }), }, { date: "2026-04-01", desktop: faker.number.int({ max: 5000, min: 1000 }), mobile: faker.number.int({ max: 5000, min: 1000 }), tablet: faker.number.int({ max: 5000, min: 1000 }), }, { date: "2026-05-01", desktop: faker.number.int({ max: 5000, min: 1000 }), mobile: faker.number.int({ max: 5000, min: 1000 }), tablet: faker.number.int({ max: 5000, min: 1000 }), }, { date: "2026-06-01", desktop: faker.number.int({ max: 5000, min: 1000 }), mobile: faker.number.int({ max: 5000, min: 1000 }), tablet: faker.number.int({ max: 5000, min: 1000 }), }, { date: "2026-07-01", desktop: faker.number.int({ max: 5000, min: 1000 }), mobile: faker.number.int({ max: 5000, min: 1000 }), tablet: faker.number.int({ max: 5000, min: 1000 }), }, { date: "2026-08-01", desktop: faker.number.int({ max: 5000, min: 1000 }), mobile: faker.number.int({ max: 5000, min: 1000 }), tablet: faker.number.int({ max: 5000, min: 1000 }), }, ], [], ) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ## Usage ```tsx import { LineChart } from "@yamada-ui/react" ``` ```tsx import { LineChart } from "@/components/ui" ``` ```tsx import { LineChart } from "@workspaces/ui" ``` ```tsx ``` ### Composition ```tsx const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM")} /> dayjs(value).format("MMM")} /> ) ``` ### Change Size ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( {(size, index) => ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> )} ) ``` ### Change Color Scheme ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Change Color ```tsx const series = useMemo[]>( () => [ { dataKey: "desktop", color: "red" }, { dataKey: "tablet", color: "blue" }, { dataKey: "mobile", color: "green" }, ], [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Change Type To change the type, set `type` in `series` or `lineProps.type` to `"monotone"`, `"linear"`, etc. The default is `"monotone"`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( {(type, index) => ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> )} ) ``` ### Add Y Axis To add the Y axis, set `withYAxis` to `true`. The default is `false`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` To change the orientation of the Y axis, set `yAxisProps.orientation` to `"start"` or `"end"`. The default is `"start"`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} yAxisProps={{ orientation: "end" }} /> ) ``` ### Add Legend To add the legend, set `withLegend` to `true`. The default is `false`. To change the placement of the legend, set `legendProps.placement` to `"start-start"`, `"end-end"`, etc. The default is `"start-end"`. ```tsx const series = useMemo[]>( () => [ { dataKey: "desktop", color: "red" }, { dataKey: "tablet", color: "blue" }, { dataKey: "mobile", color: "green" }, ], [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Change Name To change item names in the tooltip or legend, set `name` in `series`. ```tsx const series = useMemo[]>( () => [ { dataKey: "desktop", name: "Desktop", color: "red" }, { dataKey: "tablet", name: "Tablet", color: "blue" }, { dataKey: "mobile", name: "Mobile", color: "green" }, ], [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Change Grid To change the grid, set booleans in `gridProps.horizontal` and `gridProps.vertical`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( {(value, index) => ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> )} ) ``` ### Add Dot To add dots, set `dot` of `series` or `lineProps.dot` to `true`. The default is `false`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([{ dataKey: "desktop" }]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Add Label To add labels, set `label` of `series` or `lineProps.label` to `true`. The default is `false`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([{ dataKey: "desktop" }]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Add Unit To add units, use `formatter`, `tickFormatter`, or set a string in `unit`. ```tsx preview functional const series = useMemo[]>( () => LineChart.mergeSeries([{ dataKey: "desktop" }]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( `${(Number(value) / 1000).toFixed(1)}k`, }, }} tooltipProps={{ formatter: (value) => `${(Number(value) / 1000).toFixed(1)}k`, labelFormatter: (value) => dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} yAxisProps={{ domain: [0, 10000], tickFormatter: (value) => (value / 1000).toFixed(1), ticks: [0, 2500, 5000, 7500, 10000], unit: "k", }} /> ) ``` ### Sync To sync charts, set `syncId` to a string. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Format To format values, use `formatter`, `tickFormatter`, etc. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( [ Number(value).toLocaleString(), toTitleCase(name), ], labelFormatter: (value) => dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} yAxisProps={{ tickFormatter: (value) => value.toLocaleString(), }} /> ) ``` ### Add Reference Line ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} > ) ``` ### Add Tick Line To add tick lines, set `xAxisProps.tickLine` or `yAxisProps.tickLine` to `true`. The default is `false`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), tickLine: true, }} yAxisProps={{ tickLine: true }} /> ) ``` ### Add Axis Label To add axis labels, set a string in `xAxisProps.label` or `yAxisProps.label`. The default is `false`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", label: "Date", tickFormatter: (value) => dayjs(value).format("MMM"), }} yAxisProps={{ label: "Value" }} /> ) ``` ### Set Domain To set the range, set `yAxisProps.domain` to `[min, max]`. To set the interval, set an array in `yAxisProps.ticks`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} yAxisProps={{ domain: [0, 5000], ticks: [0, 1000, 2000, 3000, 4000, 5000], }} /> ) ``` ### Add Tooltip Cursor To add a tooltip cursor, set `tooltipProps.cursor` to `true`. The default is `false`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Hide X Axis To hide the X axis, set `withXAxis` to `false`. The default is `true`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( null }} /> ) ``` ### Hide Active Dot To hide active dots, set `activeDot` in `series` or `lineProps.activeDot` to `false`. The default is `true`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Hide Tooltip To hide the tooltip, set `withTooltip` to `false`. The default is `true`. ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} /> ) ``` ### Customize Axis ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", label: { color: ["red", "blue"] }, tick: { color: ["red", "blue"] }, tickFormatter: (value) => dayjs(value).format("MMM"), tickLine: { color: ["red", "blue"] }, }} yAxisProps={{ label: { color: ["red", "blue"] }, tick: { color: ["red", "blue"] }, tickLine: { color: ["red", "blue"] }, }} /> ) ``` ### Customize Dot ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet", dot: { fill: "blue" } }, { dataKey: "mobile", dot: { fill: ["white", "black"], stroke: "red", strokeWidth: 1 }, }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), contentProps: { withSwatch: false }, }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Customize Active Dot ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), contentProps: { withSwatch: false }, }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Customize Label ```tsx const series = useMemo[]>( () => [{ color: "blue", dataKey: "desktop" }], [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), contentProps: { withSwatch: false }, }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} yAxisProps={{ domain: [0, 10000], ticks: [0, 2500, 5000, 7500, 10000], }} /> ) ``` ### Customize Grid ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), contentProps: { withSwatch: false }, }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ### Customize Tooltip Cursor ```tsx const series = useMemo[]>( () => LineChart.mergeSeries([ { dataKey: "desktop" }, { dataKey: "tablet" }, { dataKey: "mobile" }, ]), [], ) const data = useMemo(() => createCartesianChartData(), []) return ( dayjs(value).format("MMM"), }} xAxisProps={{ dataKey: "date", tickFormatter: (value) => dayjs(value).format("MMM"), }} /> ) ``` ## Props