Charts
BetaVersatile visualization tool, allowing users to represent data using various types of charts for effective analysis.
Chart type
Dependencies
Charts components is built on top of Unovis (a modular data visualization framework).
Installation
Update css
Add the following tooltip styling to your tailwind.css file:
@layer base {
:root {
/* ... */
--vis-tooltip-background-color: none !important;
--vis-tooltip-border-color: none !important;
--vis-tooltip-text-color: none !important;
--vis-tooltip-shadow-color: none !important;
--vis-tooltip-backdrop-filter: none !important;
--vis-tooltip-padding: none !important;
--vis-primary-color: var(--primary);
/* change to any hsl value you want */
--vis-secondary-color: 160 81% 40%;
--vis-text-color: var(--muted-foreground);
}If you are not using css-variables for your component, you need to update the --vis-primary-color and --vis-text-color to your desired hsl values (use any "rgb to hsl" converter).
Be sure to provide dark mode styling as well.
Colors
By default, we construct the primary theme color, and secondary (--vis-secondary-color) color with different opacity for the graph.
However, you can always pass in the desired color into each chart.
<template>
<AreaChart
:data="data"
:colors="['blue', 'pink', 'orange', 'red']"
/>
</template>Custom tooltip
If you want to customize the Tooltip for the chart, you can pass customTooltip prop with a custom Vue component. The custom component would receive title and data props, check out ChartTooltip.vue component for example.
The expected prop definition would be:
defineProps<{
title?: string;
data: {
name: string;
color: string;
value: unknown;
}[];
}>();API Reference
Parts shared by every chart:
ChartTooltip
Props
| Prop | Type | Default |
|---|---|---|
titleHeading shown above the values. | string | - |
datarequiredRows to list, each with a name, color swatch, and value. | { name: string; color: string; value: any; }[] | - |
ChartSingleTooltip
Props
| Prop | Type | Default |
|---|---|---|
selectorrequiredCSS selector of the chart elements that show the tooltip on hover. | string | - |
indexrequiredData key used as the tooltip title. | string | - |
itemsLegend items used to look up the name and color of each value. | BulletLegendItemInterface[] | - |
valueFormatterFormats each value before it is shown. | ((tick: number, i?: number, ticks?: number[]) => string) | `${tick}` |
customTooltipComponent rendered instead of ChartTooltip; receives title and data props. | Component | - |
ChartLegend
Props
| Prop | Type | Default |
|---|---|---|
itemsrequiredLegend entries; inactive items are shown as filtered out. | BulletLegendItemInterface[] | [] |
Events
| Event | Payload |
|---|---|
legendItemClickEmitted when a legend item is clicked, with the item and its index. | [d: BulletLegendItemInterface, i: number] |
update:itemsEmitted with the new items after a click isolates one series or resets the filter. | [payload: BulletLegendItemInterface[]] |
ChartCrosshair
Props
| Prop | Type | Default |
|---|---|---|
colorsrequiredCrosshair point color for each series, in category order. | string[] | [] |
indexrequiredData key used as the tooltip title. | string | - |
itemsrequiredLegend items used to look up the name and color of each value. | BulletLegendItemInterface[] | - |
customTooltipComponent rendered instead of ChartTooltip; receives title and data props. | Component | - |
ChartContainer
Props
| Prop | Type | Default |
|---|---|---|
config | ChartConfig | {} |
passthrough | boolean | false |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Charts are SVG graphics. Hovering a point or bar shows a tooltip, and a donut chart lists each slice in a legend. Give the surrounding section a heading or caption that states what the chart measures. Provide the same numbers in a table when the exact values matter, and do not rely on color alone to tell series apart.
| Key | Description |
|---|---|
| Tab | Moves focus past the chart. Points, bars, and slices are not individually focusable. |