Visualizations

Chart

Chart components for visualizing data using area and bar styles with support for custom tooltips, legends, and dynamic control. They are responsive.

Installation

Install the component via the CLI in one command.

npx shadcn@latest add @intentui/chart

Manual installation

Use this approach if you prefer to install and wire up the component yourself instead of using the CLI.

npm install recharts

Hooks

For responsive charts, you can use this hook (hooks/use-mobile.ts):

import { useEffect, useState } from "react"

const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
  const [isMobile, setIsMobile] = useState<boolean | undefined>(undefined)

  useEffect(() => {
    const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
    const onChange = () => {
      setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
    }
    mql.addEventListener("change", onChange)
    setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
    return () => mql.removeEventListener("change", onChange)
  }, [])

  return !!isMobile
}

Examples

Area

Area charts are great for showing trends, comparisons, and patterns over time. They keep your data clean and easy to read.

Loading...

Bar

Bar charts help visualize data comparisons across categories. They are effective for highlighting differences and trends using vertical or horizontal bars.

Loading...

Pie

Pie charts are useful for showing how parts contribute to a whole. They are best for displaying proportions and percentages in a visually appealing way.

Loading...

Container height

When using charts, whether area, bar, or pie, you can control the container height to match your layout. Setting an explicit height ensures the chart renders correctly. If you want different heights for desktop and mobile, you can use the useIsMobile hook:

export default function App() {
  const isMobile = useIsMobile();

  return (
    <AreaChart
      containerHeight={isMobile ? 200 : 300}
      ...

If you do not set a height, the chart defaults to 370 on desktop and 200 on mobile.

Component API

CartesianGrid

The CartesianGrid component renders chart grid lines.

PropTypeDefault
classNamestring-

Chart

The Chart component provides shared chart context and layout.

PropTypeDefault
childrenReactElement | ((props: ChartContextProps) => ReactElement)-
classNamestring-
configChartConfig-
containerHeightnumber370 desktop / 200 mobile
dataRecord<string, any>[][]
dataKeystringvalue
idstringgenerated
layoutChartLayouthorizontal

ChartLegendContent

The ChartLegendContent component renders the chart legend items.

PropTypeDefault
alignLegendProps["align"]right
classNamestring-
hideIconbooleanfalse
nameKeystring-
payloadReadonlyArray<LegendPayload>-
verticalAlignLegendProps["verticalAlign"]bottom

ChartLegend

The ChartLegend component renders the chart legend container.

ChartTooltip

The ChartTooltip component renders the chart tooltip container.

ChartTooltipContent

The ChartTooltipContent component renders chart tooltip content.

PropTypeDefault
classNamestring-
colorstring-
formatterTooltipContentProps["formatter"]-
hideIndicatorbooleanfalse
hideLabelbooleanfalse
indicator"line" | "dot" | "dashed"dot
labelClassNamestring-
labelFormatterTooltipContentProps["labelFormatter"]-
labelKeystring-
labelSeparatorbooleantrue
nameKeystring-

XAxis

The XAxis component renders the chart x-axis.

PropTypeDefault
classNamestring-
displayEdgeLabelsOnlyboolean-
intervalTypeIntervalTypepreserveStartEnd
minTickGapnumber5

YAxis

The YAxis component renders the chart y-axis.

PropTypeDefault
classNamestring-
domainYAxisPrimitiveProps["domain"]["auto", "auto"]
typeYAxisPrimitiveProps["type"]layout-based
widthnumberlayout-based

See the Recharts for the full API reference.

Unlock the full power of
Intent UI Design

Build modern web apps faster with 1000+ resources across components, blocks, patterns, templates, and starter kits.

Learn more