DevExtreme Vue - Hover

User Interaction

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

  • series.hoverStyle
    The hover style for an individual series.

  • commonSeriesSettings.%seriesType%.hoverStyle
    The hover style for all series of a specific type (line, bar, etc.).

  • commonSeriesSettings.hoverStyle
    The hover style for all series in the Chart.

Note that individual settings override type-specific settings which, in turn, override common settings.

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        // ...
        series: {
            hoverStyle: {
                // high priority
            }
        },
        commonSeriesSettings: {
            bar: {
                hoverStyle: {
                    // middle priority
                }
            },
            hoverStyle: {
                // low priority
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-chart ... >
    <dxi-series ... >
        <dxo-hover-style>
            <!-- high priority -->
        </dxo-hover-style>
    </dxi-series>
    <dxo-common-series-settings ... >
        <dxo-hover-style>
            <!-- low priority -->
        </dxo-hover-style>
        <dxo-bar>
            <dxo-hover-style>
                <!-- middle priority -->
            </dxo-hover-style>
        </dxo-bar>
    </dxo-common-series-settings>
</dx-chart>
import { DxChartModule } from 'devextreme-angular';
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})

To choose which series elements should be highlighted when a user pauses on a series, specify the hoverMode option. Just like hoverStyle, this option can be specified for all series in the Chart, for all series of a specific type, or for an individual series. Note also that depending on the series type, the hoverMode option 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 hoverMode option description.

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        // ...
        commonSeriesSettings: {
            bar: {
                hoverMode: 'allSeriesPoints' // or 'onlyPoint' | 'allArgumentPoints' | 'none'
            },
            line: {
                hoverMode: 'includePoints' // or 'nearestPoint' | 'excludePoints' | 'none'
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-chart ... >
    <dxo-common-series-settings ... >
        <dxo-bar
            hoverMode="allSeriesPoints"> <!-- or 'onlyPoint' | 'allArgumentPoints' | 'none' -->
        </dxo-bar>
        <dxo-line
            hoverMode="includePoints"> <!-- or 'nearestPoint' | 'excludePoints' | 'none' -->
        </dxo-line>
    </dxo-common-series-settings>
</dx-chart>
import { DxChartModule } from 'devextreme-angular';
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})

View Demo

See Also

API

You can switch a series into the hover state by calling its hover() method, and its clearHover() method to switch it back to the normal state. The same API is available for series points.

jQuery
JavaScript
var toggleSeriesHoverState = function (series) {
    !series.isHovered() ? series.hover() : series.clearHover();        
}
Angular
TypeScript
import { DxChartModule } from 'devextreme-angular';
// ...
export class AppComponent {
    toggleSeriesHoverState (series) {
        !series.isHovered() ? series.hover() : series.clearHover();
    }
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})
See Also

Events

When a user pauses on a series, the Chart fires the seriesHoverChanged 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 onSeriesHoverChanged option when you configure the widget. To check whether the pointer entered or left a series, call the isHovered() method in the series.

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        // ...
        onSeriesHoverChanged: function (e) {
            var series = e.target;
            if (series.isHovered()) {
                // Commands to execute when the series is hovered over
            } else {
                // Commands to execute when the series is hovered out
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-chart
    (onSeriesHoverChanged)="onSeriesHoverChanged($event)">
</dx-chart>
import { DxChartModule } from 'devextreme-angular';
// ...
export class AppComponent {
    onSeriesHoverChanged (e) {
        let series = e.target;
        if (series.isHovered()) {
            // Commands to execute when the series is hovered over
        } else {
            // Commands to execute when the series is hovered out
        }
    };
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})

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

JavaScript
var seriesHoverChangedHandler1 = function (e) {
    var series = e.target;
    // First handler of the "seriesHoverChanged" event
};

var seriesHoverChangedHandler2 = function (e) {
    var series = e.target;
    // Second handler of the "seriesHoverChanged" event
};

$("#chartContainer").dxChart("instance")
    .on("seriesHoverChanged", seriesHoverChangedHandler1)
    .on("seriesHoverChanged", seriesHoverChangedHandler2);
NOTE
There are series that consist of points only, for example, bar or financial series. For these series, subscribe to the pointHoverChanged event instead of seriesHoverChanged (see the Point Hover Events topic).
See Also