API
The selection capability is not provided out of the box, but it can be implemented using the pointClick event. The following code gives an example for the scenario when a click on a point selects it, and a subsequent click on the same point clears the selection. To check whether the point is already selected, its isSelected() method is called.
jQuery
$(function() { $("#chartContainer").dxChart({ // ... onPointClick: function (e) { var point = e.target; if (point.isSelected()) { point.clearSelection(); } else { point.select(); } } }); });
Angular
<dx-chart (onPointClick)="onPointClick($event)"> </dx-chart>
import { DxChartModule } from "devextreme-angular"; // ... export class AppComponent { onPointClick (e) { let point = e.target; if (point.isSelected()) { point.clearSelection(); } else { point.select(); } }; } @NgModule({ imports: [ // ... DxChartModule ], // ... })
In the previous code example, selection was cleared of a specific point. If you need to clear selection of all points in a series, call the clearSelection() method of that series.
jQuery
$(function() { $("#chartContainer").dxChart({ // ... onPointClick: function (e) { var series = e.target.series; if (series.isSelected()) { series.clearSelection(); } else { series.select(); } } }); });
Angular
<dx-chart (onPointClick)="onPointClick($event)"> </dx-chart>
import { DxChartModule } from "devextreme-angular"; // ... export class AppComponent { onPointClick (e) { let series = e.target.series; if (series.isSelected()) { series.clearSelection(); } else { series.select(); } }; } @NgModule({ imports: [ // ... DxChartModule ], // ... })
If you need to clear selection of all series in the Chart along with their points, call the clearSelection() method of the Chart instance.
jQuery
$("#chartContainer").dxChart("clearSelection");
Angular
import { ..., ViewChild } from "@angular/core"; import { DxChartModule, DxChartComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxChartComponent) chart: DxChartComponent; clearSelection() { this.chart.instance.clearSelection(); } } @NgModule({ imports: [ // ... DxChartModule ], // ... })
See Also
- Handle Events: jQuery | Angular | AngularJS | Knockout | Vue | React | ASP.NET MVC
- Call Methods: jQuery | Angular | AngularJS | Knockout | Vue | React | ASP.NET MVC
- Access a Series Using the API
- Series Selection Using the API
User Interaction
When a user selects a series point, it changes its style to the one specified by the following objects.
series.point.selectionStyle
The selection style for all points of an individual series.commonSeriesSettings.%seriesType%.point.selectionStyle
The selection style for all points belonging to a series of a specific type (line, area, etc.).commonSeriesSettings.point.selectionStyle
The selection style for all series points in the Chart.
Note that individual settings override type-specific settings which, in turn, override common settings.
jQuery
$(function() { $("#chartContainer").dxChart({ // ... series: { point: { selectionStyle: { // high priority } } }, commonSeriesSettings: { area: { point: { selectionStyle: { // middle priority } } }, point: { selectionStyle: { // low priority } } } }); });
Angular
<dx-chart ... > <dxi-series ... > <dxo-point> <dxo-selection-style> <!-- high priority --> </dxo-selection-style> </dxo-point> </dxi-series> <dxo-common-series-settings ... > <dxo-point> <dxo-selection-style> <!-- low priority --> </dxo-selection-style> </dxo-point> <dxo-area> <dxo-point> <dxo-selection-style> <!-- middle priority --> </dxo-selection-style> </dxo-point> </dxo-area> </dxo-common-series-settings> </dx-chart>
import { DxChartModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxChartModule ], // ... })
To choose which elements should be highlighted when a user selects a point, specify the selectionMode option. Just like selectionStyle, this option can be specified for all points belonging to an individual series, or for all points belonging to a series of a specific type, or for all series points in the Chart.
jQuery
$(function() { $("#chartContainer").dxChart({ // ... commonSeriesSettings: { point: { selectionMode: 'allArgumentPoints' // or 'onlyPoint' | 'allSeriesPoints' | 'none' } } }); });
Angular
<dx-chart ... > <dxo-common-series-settings ... > <dxo-point selectionMode="allArgumentPoints"> <!-- or 'onlyPoint' | 'allSeriesPoints' | 'none' --> </dxo-point> </dxo-common-series-settings> </dx-chart>
import { DxChartModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxChartModule ], // ... })
By default, only a single point can be in the selected state at a time. If you need to allow multiple points to be in this state, assign "multiple" to the pointSelectionMode option.
jQuery
$(function() { $("#chartContainer").dxChart({ // ... pointSelectionMode: 'multiple' // or 'single' }); });
Angular
<dx-chart pointSelectionMode="multiple"> <!-- or 'single' --> </dx-chart>
import { DxChartModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxChartModule ], // ... })
See Also
Events
When a user selects a series point, the Chart fires the pointSelectionChanged event that you can handle with a function. If the handling function is not going to be changed during the lifetime of the widget, assign it to the onPointSelectionChanged option when you configure the widget. To check whether a point was selected or the selection was cleared, call the isSelected() method of the point.
jQuery
$(function() { $("#chartContainer").dxChart({ // ... onPointSelectionChanged: function (e) { var point = e.target; if (point.isSelected()) { // Commands to execute when the point is selected } else { // Commands to execute when the selection is cleared } } }); });
Angular
<dx-chart (onPointSelectionChanged)="onPointSelectionChanged($event)"> </dx-chart>
import { DxChartModule } from "devextreme-angular"; // ... export class AppComponent { onPointSelectionChanged (e) { let point = e.target; if (point.isSelected()) { // Commands to execute when the point is selected } else { // Commands to execute when the selection is cleared } }; } @NgModule({ imports: [ // ... DxChartModule ], // ... })
If you are going to change the event handler at runtime, or if you need to attach several handlers to the pointSelectionChanged event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.
var pointSelectionChangedHandler1 = function (e) { var point = e.target; // First handler of the "pointSelectionChanged" event }; var pointSelectionChangedHandler2 = function (e) { var point = e.target; // Second handler of the "pointSelectionChanged" event }; $("#chartContainer").dxChart("instance") .on("pointSelectionChanged", pointSelectionChangedHandler1) .on("pointSelectionChanged", pointSelectionChangedHandler2);
See Also
- Handle Events: jQuery | Angular | AngularJS | Knockout | Vue | React | ASP.NET MVC
- Series Selection Events
- Chart API Reference
If you have technical questions, please create a support ticket in the DevExpress Support Center.