The legend is shown by default. You can hide it by setting the hideLegend prop to true.
<LineChart :hide-legend="true" />
Control the legend's position using the legendPosition prop. Supported values:
topLefttopCentertopRightbottomLeftbottomCenterbottomRightThe legend is rendered above or below the chart depending on the position. The component uses computed properties to determine flex direction and alignment.
<LineChart :legend-position="LegendPosition.TopRight" />
Customize the legend's appearance with the legendStyle prop, which accepts a style object. The legend also uses the CSS variable --vis-legend-spacing for spacing between items.
<LineChart :legend-style="{ background: '#fff', borderRadius: '8px' }" />
You can customize the spacing around the chart legend using the --vis-legend-spacing CSS variable. This controls the margin or padding applied to the legend area.
Example:
:root {
--vis-legend-spacing: 16px;
}
Adjust the value as needed to fit your design.
Each legend item corresponds to a category in the categories prop. The color for each item is taken from the category's color property. If the color is an array, only the first color is used for the legend bullet.
const categories = {
sales: { name: 'Sales', color: '#22c55e' },
profit: { name: 'Profit', color: ['#3b82f6', '#a21caf'] },
}
<LineChart
:categories="categories"
legend-position="bottomCenter"
:legend-style="{ padding: '8px' }"
/>
| Prop | Type | Description |
|---|---|---|
| hideLegend | boolean | Hides the legend if true. |
| legendPosition | LegendPosition | Sets the legend's position. |
| legendStyle | object | Custom CSS styles for the legend. |
| categories | Record<string, Category> | Defines legend items and their colors. |