Skip to content

ChartContainer

Configuration object for chart data series.

Bar Chart Story

Usage

tsx
import { ChartContainer, useChart, ChartTooltipContent, ChartLegendContent } from '@tryvienna/ui'

<div className="w-[400px]">
  <ChartContainer config={barConfig}>
    <BarChart data={barData}>
      <CartesianGrid vertical={false} />
      <XAxis dataKey="month" tickLine={false} axisLine={false} />
      <YAxis tickLine={false} axisLine={false} />
      <ChartTooltip content={<ChartTooltipContent />} />
      <ChartLegend content={<ChartLegendContent />} />
      <Bar dataKey="revenue" fill="var(--color-revenue)" radius={4} />
      <Bar dataKey="expenses" fill="var(--color-expenses)" radius={4} />
    </BarChart>
  </ChartContainer>
</div>

Examples

Bar Chart Story

Bar Chart Story
tsx
<div className="w-[400px]">
  <ChartContainer config={barConfig}>
    <BarChart data={barData}>
      <CartesianGrid vertical={false} />
      <XAxis dataKey="month" tickLine={false} axisLine={false} />
      <YAxis tickLine={false} axisLine={false} />
      <ChartTooltip content={<ChartTooltipContent />} />
      <ChartLegend content={<ChartLegendContent />} />
      <Bar dataKey="revenue" fill="var(--color-revenue)" radius={4} />
      <Bar dataKey="expenses" fill="var(--color-expenses)" radius={4} />
    </BarChart>
  </ChartContainer>
</div>

Line Chart Story

Line Chart Story
tsx
<div className="w-[400px]">
  <ChartContainer config={lineConfig}>
    <LineChart data={lineData}>
      <CartesianGrid vertical={false} />
      <XAxis dataKey="month" tickLine={false} axisLine={false} />
      <YAxis tickLine={false} axisLine={false} />
      <ChartTooltip content={<ChartTooltipContent />} />
      <ChartLegend content={<ChartLegendContent />} />
      <Line
        type="monotone"
        dataKey="users"
        stroke="var(--color-users)"
        strokeWidth={2}
        dot={false}
      />
      <Line
        type="monotone"
        dataKey="sessions"
        stroke="var(--color-sessions)"
        strokeWidth={2}
        dot={false}
      />
    </LineChart>
  </ChartContainer>
</div>

Pie Chart Story

Pie Chart Story
tsx
<div className="w-[400px]">
  <ChartContainer config={pieConfig}>
    <PieChart>
      <ChartTooltip content={<ChartTooltipContent nameKey="name" />} />
      <ChartLegend content={<ChartLegendContent nameKey="name" />} />
      <Pie
        data={pieData}
        dataKey="value"
        nameKey="name"
        cx="50%"
        cy="50%"
        innerRadius={60}
        outerRadius={100}
      />
    </PieChart>
  </ChartContainer>
</div>

API Reference

ChartContainer

PropTypeDefaultDescription
idstring | undefined-
configChartConfig-

Also accepts all props from RechartsPrimitive.ResponsiveContainer.

useChart

useChart — Access chart configuration context.

ChartTooltipContent

ChartTooltipContent — Styled tooltip content for Recharts charts.

PropTypeDefaultDescription
activeboolean | undefined-
payloadPayload&lt;ValueType, NameType&gt;[] | undefined-
indicator"line" | "dot" | "dashed"dot
hideLabelbooleanfalse
hideIndicatorbooleanfalse
labelany-
labelFormatter((label: any, payload: Payload&lt;ValueType, NameType&gt;[]) =&gt; React.ReactNode) | undefined-
labelClassNamestring | undefined-
formatterFormatter&lt;ValueType, NameType&gt; | undefined-
colorstring | undefined-
nameKeystring | undefined-
labelKeystring | undefined-

Also accepts all props from RechartsPrimitive.Tooltip.

ChartLegendContent

ChartLegendContent — Styled legend content for Recharts charts.

PropTypeDefaultDescription
hideIconbooleanfalse
payloadPayload[] | undefined-
verticalAlignVerticalAlignmentTypebottom
nameKeystring | undefined-

Also accepts all props from div.

Data Attributes

Componentdata-slot
ChartContainer"chart"
useChart"use-chart"
ChartTooltipContent"chart-tooltip-content"
ChartLegendContent"chart-legend-content"