Charts
Chart components without dependencies: bar chart, horizontal bars, line chart, donut, pie and sparkline, drawn with SVG, with tooltips and an accessible summary.
How to use it
Run npx @blossomui/react add charts, or copy src/components/UI/Charts/Charts.tsx into your React project and import it.
import { Sparkline, BarChart, LineChart, DonutChart, AreaChart, RadarChart, Gauge, Heatmap } from './components/ui/Charts'
Props
ChartDatum
| Prop | Type | Description |
|---|
| label (required) | string | |
| value (required) | number | |
| color | string | Any CSS color. Defaults to the palette. |
SparklineProps
| Prop | Type | Description |
|---|
| data (required) | number[] | |
| color | string | |
| filled | boolean | Fill the area under the line. |
| height | number | Height in pixels. The width fills the container. |
| label | string | |
BarChartProps
| Prop | Type | Description |
|---|
| data (required) | ChartDatum[] | |
| height | number | Height of the chart in pixels when it is vertical. |
| horizontal | boolean | |
| showValues | boolean | Show the value of each bar. |
| label | string | Name of what is measured, used for screen readers. |
LineChartProps
| Prop | Type | Description |
|---|
| data (required) | ChartDatum[] | |
| height | number | |
| color | string | |
| filled | boolean | Fill the area under the line. |
| label | string | |
DonutChartProps
| Prop | Type | Description |
|---|
| data (required) | ChartDatum[] | |
| size | number | Diameter in pixels. |
| pie | boolean | Use a full circle without the hole. |
| center | ReactNode | Text in the center of the donut, for example the total. |
| legend | boolean | Show the list of values next to the chart. Hovering a slice always shows its value, so you can turn the list off. |
| label | string | |
Series
| Prop | Type | Description |
|---|
| name (required) | string | |
| data (required) | number[] | One value for each label of the chart. |
| color | string | Any CSS color. Defaults to the palette. |
AreaChartProps
| Prop | Type | Description |
|---|
| labels (required) | string[] | Names of the points on the horizontal axis. |
| series (required) | Series[] | |
| stacked | boolean | Pile the series on top of each other, so the top line is the total. |
| height | number | |
| legend | boolean | Show the name of each series under the chart. |
| label | string | |
RadarSeries
| Prop | Type | Description |
|---|
| name (required) | string | |
| values (required) | number[] | One value for each axis. |
| color | string | |
RadarChartProps
| Prop | Type | Description |
|---|
| axes (required) | string[] | Names of the axes, from the top and clockwise. |
| series (required) | RadarSeries[] | |
| max | number | Value at the border of the chart. By default the biggest value. |
| size | number | Diameter in pixels, labels included. |
| rings | number | Number of rings. |
| legend | boolean | |
| label | string | |
GaugeThreshold
| Prop | Type | Description |
|---|
| from (required) | number | The color applies from this value on. |
| color (required) | string | |
GaugeProps
| Prop | Type | Description |
|---|
| value (required) | number | |
| min | number | |
| max | number | |
| size | number | Width in pixels. The height is half of it. |
| caption | ReactNode | Text under the number, for example "CPU". |
| unit | string | Text added after the number, for example "%". |
| thresholds | GaugeThreshold[] | Change the color as the value grows, for example green, yellow and red. Without it the gauge uses the first color of the palette. |
| label | string | |
HeatmapProps
| Prop | Type | Description |
|---|
| data (required) | number[][] | One list of numbers for each row. Every row has one number for each column. |
| rows (required) | string[] | |
| columns (required) | string[] | |
| color | string | Color of the biggest value. The smaller ones are lighter. Defaults to the brand color. |
| showValues | boolean | Show the number inside each cell. |
| cell | number | Size of a cell in pixels. |
| label | string | |