Getting Started

Out of the box, React Charts is very forgiving and requires very little to use. Let's get started by going over the bare minimum configuration required to render a chart!

  • An array of Series objects (more on this in a bit), each with a data property that is an array of Datums (be patient, we'll explain soon!)
type DailyStars = {
date: Date,
stars: number,
}
type Series = {
label: string,
data: DailyStars[]
}
const data: Series[] = [
{
label: 'React Charts",
data: [
{
date: new Date(),
stars: 202123,
}
// ...
]
},
{
label: 'React Query",
data: [
{
date: new Date(),
stars: 10234230,
}
// ...
]
}
]
  • primaryAxis: AxisOptions<TDatum>
    • Primary Value Accessor
  • secondaryAxes: AxisOptions<TDatum>[]
    • Primary Value Accessor
function App() {
const primaryAxis = React.useMemo(
(): AxisOptions<DailyStars> => ({
getValue: datum => datum.date,
}),
[]
)
const secondaryAxes = React.useMemo(
(): AxisOptions<DailyStars>[] => [
{
getValue: datum => datum.stars,
},
],
[]
)
return (
<Chart
options={{
data,
primaryAxis,
secondaryAxes,
}}
/>
)
}

Now that you know how to build a simple chart, let's dive deeper!

Was this page helpful?

Resources

Subscribe to our newsletter

The latest TanStack news, articles, and resources, sent to your inbox.

    I won't send you spam.

    Unsubscribe at any time.

    © 2020 Tanner Linsley. All rights reserved.