export const title = "Line & bar chart components" export const description = "Free and open-source React line and bar chart components built for modern applications and websites. These line and bar charts are built using Recharts and styled with Tailwind CSS." export const links = { github: "https://github.com/untitleduico/react/tree/main/components/application/charts", recharts: "https://recharts.org/en-US/api/LineChart", } import * as LineCharts from "@/components/application/charts/line-charts.story.tsx"; import * as BarCharts from "@/components/application/charts/bar-charts.story.tsx"; ## Installation You can add this line and bar charts component using our CLI or manually: ```bash npx untitledui@latest add charts-base ``` As our line and bar charts component is built with [Recharts](https://recharts.org/en-US/), you'll need to install the dependencies: ```bash npm install recharts ``` Copy the files below into your project: Great! Now you can start using the line and bar charts components in your project by just copy/pasting our examples below. ## Chart examples Below are examples and variations of this line and bar charts component: ### Line chart 01 {{ tocOnly:true }} ### Line chart 02 {{ tocOnly:true }} ### Line chart 03 {{ tocOnly:true }} ### Line chart 04 {{ tocOnly:true }} ### Bar chart 01 {{ tocOnly:true }} ### Bar chart 02 {{ tocOnly:true }} ### Bar chart 03 {{ tocOnly:true }} ## API reference ` at the x value and give each `` or `` its own `dataKey` such as `\"A\"`.", }, { question: "Which parts are Untitled UI and which are Recharts?", answer: "`charts-base.tsx` only adds presentation helpers — `ChartTooltipContent`, `ChartLegendContent`, `ChartActiveDot`, and the `selectEvenlySpacedItems` utility. Everything structural (`ResponsiveContainer`, `AreaChart`, `BarChart`, `ComposedChart`, `XAxis`, `YAxis`, `CartesianGrid`, `Tooltip`, `Legend`, `Area`, `Bar`, `Line`, `Label`) is imported directly from `recharts`, so the entire Recharts API stays available to you. `npx untitledui@latest add charts-base` adds the helpers; for a manual setup, run `npm install recharts` and copy the file.", }, { question: "How do I use the styled tooltip?", answer: "Pass it as the `content` of the Recharts tooltip: `} />`. It respects the `formatter` and `labelFormatter` you set on `` itself — the examples use `formatter={(value) => Number(value).toLocaleString()}` for values and a `labelFormatter` that turns the date key into a readable month and year.", }, { question: "How do I change the color of a series?", answer: "No colors are hardcoded. Each series sets `stroke=\"currentColor\"` (lines and areas) or `fill=\"currentColor\"` (bars) and takes its actual color from a Tailwind class on the series' `className`, such as `text-utility-brand-600` or `text-utility-brand-400`. Change that utility class to recolor the series, and it will follow your theme in both light and dark mode. Gradient area fills work the same way: the `` elements inside the `` use `stopColor=\"currentColor\"` with their own utility class.", }, { question: "Can I customize the legend?", answer: "Yes, pass `content={}` to Recharts' ``. `ChartLegendContent` reads the `layout` you set on `` to switch between a horizontal row and a vertical column — `layout=\"vertical\"` stacks the entries, anything else lays them out in a row. The `align` you set only controls how the entries are justified within that row or column. It also accepts its own `className` plus a `reversed` boolean to flip the order of the entries.", }, { question: "How do I control how many labels appear on the x-axis?", answer: "Use the `selectEvenlySpacedItems(data, count)` helper from `charts-base` to pick evenly spaced entries from your data and pass the result to the `ticks` prop of `` — two of the bar chart examples do this with `ticks={selectEvenlySpacedItems(data, 12).map((item) => item.date)}` to reduce a long weekly dataset down to twelve labels. Setting `interval=\"preserveStartEnd\"` also keeps the first and last labels visible.", }, { question: "Are the charts responsive?", answer: "Yes. Every example is wrapped in Recharts' `ResponsiveContainer` with `initialDimension={{ width: 1, height: 1 }}`, and the chart height comes from a Tailwind class such as `h-60` on the container or its wrapper rather than a fixed pixel value. The examples also call the `useBreakpoint(\"lg\")` hook to adjust chart margins, the legend `layout`, and `maxBarSize` between mobile and desktop.", }, ]} />