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.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- onPointClick: function (e) {
- var point = e.target;
- if (point.isSelected()) {
- point.clearSelection();
- } else {
- point.select();
- }
- }
- });
- });
In the previous code example, selection was cleared of a specific point. If you need to clear selection of all points in a series, you can use the deselectPoint(point) method of that series.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- onPointClick: function (e) {
- e.target.series.getAllPoints(function(point) {
- series.deselectPoint(point);
- });
- }
- });
- });
If you need to clear selection of all series in the Chart along with their points, call the clearSelection() method of the Chart instance.
- $("#chartContainer").dxChart("clearSelection");
See Also
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.point.selectionStyle
The selection style for all series points in the Chart.
Individual series settings override common settings.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- series: {
- point: {
- selectionStyle: {
- // high priority
- }
- }
- },
- commonSeriesSettings: {
- point: {
- selectionStyle: {
- // low priority
- }
- }
- }
- });
- });
To choose which elements should be highlighted when a user selects a point, specify the selectionMode property. Just like selectionStyle, this property can be specified for all points belonging to an individual series or for all series points in the Chart.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- commonSeriesSettings: {
- point: {
- selectionMode: 'allArgumentPoints' // or 'onlyPoint' | 'allSeriesPoints' | 'none'
- }
- }
- });
- });
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 property.
- $(function() {
- $("#chartContainer").dxChart({
- // ...
- pointSelectionMode: 'multiple' // or 'single'
- });
- });
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 UI component, assign it to the onPointSelectionChanged property when you configure the UI component. To check whether a point was selected or the selection was cleared, call the isSelected() method of the point.
- $(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
- }
- }
- });
- });
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.
- 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
If you have technical questions, please create a support ticket in the DevExpress Support Center.