Vue Chart - Selection

API

The selection capability is not provided out of the box, but it can be implemented using the seriesClick event. The following code gives an example for the scenario when a click on a series selects it, and a subsequent click on the same series clears the selection. To check whether the series is already selected, its isSelected() method is called.

App.vue
  • <template>
  • <DxChart
  • @series-click="onSeriesClick"
  • >
  • </DxChart>
  • </template>
  •  
  • <script>
  • import DxChart from 'devextreme-vue/chart';
  •  
  • export default {
  • components: {
  • DxChart
  • },
  • methods: {
  • onSeriesClick (e) {
  • const series = e.target;
  • if (series.isSelected()) {
  • series.clearSelection();
  • } else {
  • series.select();
  • }
  • }
  • }
  • }
  • </script>

There are series that consist of points only, for example, bar or financial series. For these series, subscribe to the pointClick event instead of seriesClick.

App.vue
  • <template>
  • <DxChart
  • @point-click="onPointClick"
  • >
  • </DxChart>
  • </template>
  •  
  • <script>
  • import DxChart from 'devextreme-vue/chart';
  •  
  • export default {
  • components: {
  • DxChart
  • },
  • methods: {
  • onPointClick (e) {
  • const series = e.target.series;
  • if (series.isSelected()) {
  • series.clearSelection();
  • } else {
  • series.select();
  • }
  • }
  • }
  • }
  • </script>

In the previous code examples, selection was cleared of a specific series. If you need to clear selection of all series, call the clearSelection() method in the Chart instance.

App.vue
  • <template>
  • <DxChart ref="chart">
  • </DxChart>
  • </template>
  •  
  • <script>
  • import DxChart from 'devextreme-vue/chart';
  •  
  • export default {
  • components: {
  • DxChart
  • },
  • methods: {
  • clearSelection () {
  • return this.$refs.chart.instance.clearSelection();
  • }
  • }
  • }
  • </script>
See Also

User Interaction

When a user selects a series, the series changes its style to the one specified by the following objects.

  • series.selectionStyle
    The selection style for an individual series.

  • commonSeriesSettings.selectionStyle
    The selection style for all series in the Chart.

Individual settings override common settings.

App.vue
  • <template>
  • <DxChart ... >
  • <DxSeries ... >
  • <DxSelectionStyle>
  • <!-- high priority -->
  • </DxSelectionStyle>
  • </DxSeries>
  • <DxCommonSeriesSettings ... >
  • <DxSelectionStyle>
  • <!-- low priority -->
  • </DxSelectionStyle>
  • </DxCommonSeriesSettings>
  • </DxChart>
  • </template>
  •  
  • <script>
  • import DxChart, {
  • DxSeries,
  • DxCommonSeriesSettings,
  • DxSelectionStyle
  • } from 'devextreme-vue/chart';
  •  
  • export default {
  • components: {
  • DxChart,
  • DxSeries,
  • DxCommonSeriesSettings,
  • DxSelectionStyle
  • }
  • }
  • </script>

To choose which series elements should be highlighted when a user selects a series, specify the selectionMode property. Just like selectionStyle, this property can be specified for all series in the Chart or for an individual series. Depending on the series type, the selectionMode property accepts different values. For information about them, visit the Series Types section of the API reference, choose the employed series type, and refer to its selectionMode property description.

App.vue
  • <template>
  • <DxChart ... >
  • <DxSeries
  • type="bar"
  • selection-mode="allSeriesPoints" <!-- or "onlyPoint" | "allArgumentPoints" | "none" -->
  • />
  • <DxSeries
  • type="line"
  • selection-mode="includePoints" <!-- or "nearestPoint" | "excludePoints" | "none" -->
  • />
  • </DxChart>
  • </template>
  •  
  • <script>
  • import DxChart, {
  • DxSeries
  • } from 'devextreme-vue/chart';
  •  
  • export default {
  • components: {
  • DxChart,
  • DxSeries
  • }
  • }
  • </script>

View Demo

By default, only a single series can be in the selected state at a time. If you need to allow multiple series to be in this state, assign "multiple" to the seriesSelectionMode property.

App.vue
  • <template>
  • <DxChart
  • ...
  • series-selection-mode="multiple"> <!-- or 'single' -->
  • >
  • </DxChart>
  • </template>
  •  
  • <script>
  • import DxChart from 'devextreme-vue/chart';
  •  
  • export default {
  • components: {
  • DxChart
  • }
  • }
  • </script>

View Demo

See Also

Events

When a user selects a series, the Chart fires the seriesSelectionChanged event that you can handle with a function. If the handling function is not going to be changed during the lifetime of the UI component, assign it to the onSeriesSelectionChanged property when you configure the UI component. To check whether a series was selected or the selection was cleared, call the isSelected() method of the series.

App.vue
  • <template>
  • <DxChart
  • @series-selection-changed="onSeriesSelectionChanged"
  • >
  • </DxChart>
  • </template>
  •  
  • <script>
  • import DxChart from 'devextreme-vue/chart';
  •  
  • export default {
  • components: {
  • DxChart
  • },
  • methods: {
  • onSeriesSelectionChanged (e) {
  • const series = e.target;
  • if (series.isSelected()) {
  • // Commands to execute when the series is selected
  • } else {
  • // Commands to execute when the selection is cleared
  • }
  • }
  • }
  • }
  • </script>

If you are going to change the event handler at runtime or if you need to attach several handlers to the seriesSelectionChanged event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
  • var seriesSelectionChangedHandler1 = function (e) {
  • var series = e.target;
  • // First handler of the "seriesSelectionChanged" event
  • };
  •  
  • var seriesSelectionChangedHandler2 = function (e) {
  • var series = e.target;
  • // Second handler of the "seriesSelectionChanged" event
  • };
  •  
  • $("#chartContainer").dxChart("instance")
  • .on("seriesSelectionChanged", seriesSelectionChangedHandler1)
  • .on("seriesSelectionChanged", seriesSelectionChangedHandler2);
NOTE
There are series that consist of points only, for example, bar or financial series. For these series, subscribe to the pointSelectionChanged event instead of seriesSelectionChanged (see the Point Selection Events topic).
See Also