Vue Chart - legend
The Chart widget can include a legend - an explanatory component that helps you identify a series. Each series is represented by an item on a Legend. An item marker identifies the series color. An item label displays the series title. To set the required position for a legend and its items, to customize the font settings for item labels, and to specify the size of item markers, use the properties of the legend configuration object. To learn more on the legend and its options, refer to the Legend topic.
backgroundColor
This option supports the following colors:
- Hexadecimal colors
- RGB colors
- RGBA colors
- Predefined/cross-browser color names
- Predefined SVG colors
columnCount
Use this option when the legend is oriented vertically. Otherwise, use rowCount.
See Also
- legend.columnItemSpacing
customizeHint
Name | Type | Description |
---|---|---|
seriesColor |
The series' color. |
|
seriesIndex |
The index of the series in the series array. To get the Series object by this index, call the getSeriesByPos(seriesIndex) method. |
|
seriesName | any |
The series' name. To get the Series object by this name, call the getSeriesByName(seriesName) method. |
customizeItems
Array<BaseChartLegendItem>
Array<BaseChartLegendItem>
The following code shows how to use the customizeItems function to sort legend items alphabetically:
jQuery
$(function() { $("#chartContainer").dxChart({ // ... legend: { customizeItems: function(items) { return items.sort(function(a, b) { var itemA = a.text.toLowerCase(); var itemB = b.text.toLowerCase(); if(itemA < itemB) return -1; if(itemA > itemB) return 1; return 0; }); } } }); });
Angular
<dx-chart ... > <dxo-legend ... [customizeItems]="sortLegendItems"> </dxo-legend> </dx-chart>
// ... export class AppComponent { sortLegendItems(items) { return items.sort((a, b) => { let itemA = a.text.toLowerCase(); let itemB = b.text.toLowerCase(); if(itemA < itemB) return -1; if(itemA > itemB) return 1; return 0; }); } }
import { DxChartModule } from 'devextreme-angular'; // ... @NgModule({ imports: [ // ... DxChartModule ], // ... }) export class AppModule { }
Vue
<template> <DxChart ... > <DxLegend :customize-items="sortLegendItems" /> </DxChart> </template> <script> import { DxChart, DxLegend } from 'devextreme-vue/chart'; export default { components: { DxChart, DxLegend }, methods: { sortLegendItems(items) { return items.sort((a, b) => { let itemA = a.text.toLowerCase(); let itemB = b.text.toLowerCase(); if(itemA < itemB) return -1; if(itemA > itemB) return 1; return 0; }); } } } </script>
React
import React from 'react'; import { Chart, Legend } from 'devextreme-react/chart'; class App extends React.Component { render() { return ( <Chart ... > <Legend ... customizeItems={this.sortLegendItems} /> </Chart> ); } sortLegendItems(items) { return items.sort((a, b) => { let itemA = a.text.toLowerCase(); let itemB = b.text.toLowerCase(); if(itemA < itemB) return -1; if(itemA > itemB) return 1; return 0; }); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().Chart() @* ... *@ .Legend(l => l .CustomizeItems("sortLegendItems") ) ) <script type="text/javascript"> function sortLegendItems (items) { return items.sort(function(a, b) { var itemA = a.text.toLowerCase(); var itemB = b.text.toLowerCase(); if(itemA < itemB) return -1; if(itemA > itemB) return 1; return 0; }); } </script>
horizontalAlignment
Along with verticalAlignment, specifies the legend's position.
Use the HorizontalAlignment
enum to specify this option when the widget is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Left
, Center
, and Right
.
See Also
- legend.orientation
hoverMode
Specifies what series elements to highlight when a corresponding item in the legend is hovered over.
In the Chart widget, legend items represent series. When a legend item is hovered over, the corresponding series is highlighted. To prevent this behavior, set the hoverMode property to 'none'.
You can set a custom 'hover' style for a series and/or its points. To do this, use the series' hoverStyle configuration object and/or the point.hoverStyle configuration object.
Use the ChartLegendHoverMode
enum to specify this option when the widget is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: IncludePoints
, ExcludePoints
, and None
.
itemsAlignment
Aligns items in the last column or row (depending on the legend's orientation). Applies when legend items are not divided into columns or rows equally.
Use the HorizontalAlignment
enum to specify this option when the widget is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Left
, Center
, and Right
.
orientation
Arranges legend items vertically (in a column) or horizontally (in a row). The default value is "horizontal" if the legend.horizontalAlignment is "center". Otherwise, it is "vertical".
Use the Orientation
enum to specify this option when the widget is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Horizontal
and Vertical
.
See Also
- legend.verticalAlignment
- legend.horizontalAlignment
position
In addition to this option, use the legend's horizontalAlignment, verticalAlignment and orientation options to specify the legend layout.
Use the RelativePosition
enum to specify this option when the widget is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Inside
and Outside
.
rowCount
Use this option when the legend is oriented horizontally. Otherwise, use columnCount.
See Also
- legend.rowItemSpacing
title
To specify only the title's text, assign it directly to this option. Otherwise, set this option to an object with the text and other fields specified.
The title can be accompanied by a subtitle. Assign it to the title.subtitle option.
verticalAlignment
Along with horizontalAlignment, specifies the legend's position.
Use the VerticalEdge
enum to specify this option when the widget is used as an ASP.NET MVC 5 Control or a DevExtreme-Based ASP.NET Core Control. This enum accepts the following values: Top
and Bottom
.
See Also
- legend.orientation
If you have technical questions, please create a support ticket in the DevExpress Support Center.