Vue Chart - Hover

User Interaction

NOTE
Range Bar and Bubble, all bar and financial series do not contain anything besides points. Therefore, configuring points in these series is, in fact, configuring the series itself. For this reason, follow the instructions given in the Series Hover - User Interaction topic when you configure hovering for points that belong to the aforementioned series.

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

  • series.point.hoverStyle
    The hover style for all points of an individual series.

  • commonSeriesSettings.point.hoverStyle
    The hover style for all series points in the Chart. Individual series settings override common settings.

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        // ...
        series: {
            point: {
                hoverStyle: {
                    // high priority
                }
            }
        },
        commonSeriesSettings: {
            point: {
                hoverStyle: {
                    // low priority
                }
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-chart ... >
    <dxi-series ... >
        <dxo-point>
            <dxo-hover-style>
                <!-- high priority -->
            </dxo-hover-style>
        </dxo-point>
    </dxi-series>
    <dxo-common-series-settings ... >
        <dxo-point>
            <dxo-hover-style>
                <!-- low priority -->
            </dxo-hover-style>
        </dxo-point>
    </dxo-common-series-settings>
</dx-chart>
import { DxChartModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxChart ... >
        <DxSeries>
            <DxPoint ... >
                <DxHoverStyle>
                    <!-- high priority -->
                </DxHoverStyle>
            </DxPoint>
        </DxSeries>
        <DxCommonSeriesSettings ... >
            <DxPoint ... >
                <DxHoverStyle>
                    <!-- low priority -->
                </DxHoverStyle>
            </DxPoint>
        </DxCommonSeriesSettings>
    </DxChart>
</template>

<script>
import DxChart, {
    DxCommonSeriesSettings,
    DxSeries,
    DxPoint,
    DxHoverStyle
} from 'devextreme-vue/chart';

export default {
    components: {
        DxChart,
        DxCommonSeriesSettings,
        DxSeries,
        DxPoint,
        DxHoverStyle
    }
}
</script>
React
App.js
import React from 'react';
import Chart, {
    CommonSeriesSettings,
    Series,
    Point,
    HoverStyle
} from 'devextreme-react/chart';

class App extends React.Component {
    render() {
        return (
            <Chart ... >
                <Series>
                    <Point ... >
                        <HoverStyle>
                            {/* high priority */}
                        </HoverStyle>
                    </Point>
                </Series>
                <CommonSeriesSettings ... >
                    <Point ... >
                        <HoverStyle>
                            {/* low priority */}
                        </HoverStyle>
                    </Point>
                </CommonSeriesSettings>
            </Chart>
        );
    }
}

export default App;

To choose which series elements should be highlighted when a user pauses on a series point, specify the hoverMode property. Just like hoverStyle above, this property can be specified for all points belonging to an individual series or for all series points in the Chart.

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        // ...
        commonSeriesSettings: {
            point: {
                hoverMode: 'allArgumentPoints' // or 'onlyPoint' | 'allSeriesPoints' | 'none'
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-chart ... >
    <dxo-common-series-settings ... >
        <dxo-point
            hoverMode="allArgumentPoints"> <!-- or 'onlyPoint' | 'allSeriesPoints' | 'none' -->
        </dxo-point>
    </dxo-common-series-settings>
</dx-chart>
import { DxChartModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxChart ... >
        <DxCommonSeriesSettings ... >
            <DxPoint
                hover-mode="allArgumentPoints"/> <!-- or 'onlyPoint' | 'allSeriesPoints' | 'none' -->
        </DxCommonSeriesSettings>
    </DxChart>
</template>

<script>
import DxChart, {
    DxCommonSeriesSettings,
    DxPoint
} from 'devextreme-vue/chart';

export default {
    components: {
        DxChart,
        DxCommonSeriesSettings,
        DxPoint
    }
}
</script>
React
App.js
import React from 'react';
import Chart, {
    CommonSeriesSettings,
    Point
} from 'devextreme-react/chart';

class App extends React.Component {
    render() {
        return (
            <Chart ... >
                <CommonSeriesSettings ... >
                    <Point
                        hoverMode="allArgumentPoints" /> {/* or 'onlyPoint' | 'allSeriesPoints' | 'none' */}
                </CommonSeriesSettings>
            </Chart>
        );
    }
}

export default App;

View Demo

See Also

API

You can switch a point 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.

jQuery
JavaScript
var togglePointHoverState = function (point) {
    !point.isHovered() ? point.hover() : point.clearHover();        
}
Angular
TypeScript
import { DxChartModule } from "devextreme-angular";
// ...
export class AppComponent {
    togglePointHoverState (point) {
        !point.isHovered() ? point.hover() : point.clearHover();
    }
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxChart ... >
    </DxChart>
</template>

<script>
import DxChart from 'devextreme-vue/chart';

export default {
    components: {
        DxChart
    },
    methods: {
        togglePointHoverState (point) {
            !point.isHovered() ? point.hover() : point.clearHover();
        }
    }
}
</script>
React
App.js
import React from 'react';
import Chart from 'devextreme-react/chart';

class App extends React.Component {
    render() {
        return (
            <Chart ... >
            </Chart>
        );
    }

    togglePointHoverState (point) {
        !point.isHovered() ? point.hover() : point.clearHover();
    }

}

export default App;
See Also

Events

When a user pauses on a series point, the Chart fires the pointHoverChanged 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 onPointHoverChanged property when you configure the UI component. To check whether the pointer entered or left a series, call the isHovered() method of the series.

jQuery
JavaScript
$(function() {
    $("#chartContainer").dxChart({
        // ...
        onPointHoverChanged: function (e) {
            var point = e.target;
            if (point.isHovered()) {
                // Commands to execute when the point is hovered over
            } else {
                // Commands to execute when the point is hovered out
            }
        }
    });
});
Angular
HTML
TypeScript
<dx-chart
    (onPointHoverChanged)="onPointHoverChanged($event)">
</dx-chart>
import { DxChartModule } from "devextreme-angular";
// ...
export class AppComponent {
    onPointHoverChanged (e) {
        const point = e.target;
        if (point.isHovered()) {
            // Commands to execute when the point is hovered over
        } else {
            // Commands to execute when the point is hovered out
        }
    };
}
@NgModule({
    imports: [
        // ...
        DxChartModule
    ],
    // ...
})
Vue
App.vue
<template> 
    <DxChart
        @point-hover-changed="onPointHoverChanged($event)"
        ...
    >
    </DxChart>
</template>

<script>
import DxChart from 'devextreme-vue/chart';

export default {
    components: {
        DxChart
    },
    methods: {
        onPointHoverChanged (e) {
            const point = e.target;
            if (point.isHovered()) {
                // Commands to execute when the point is hovered over
            } else {
                // Commands to execute when the point is hovered out
            }
        }
    }
}
</script>
React
App.js
import React from 'react';
import Chart from 'devextreme-react/chart';

class App extends React.Component {
    render() {
        return (
            <Chart
                onPointHoverChanged={this.onPointHoverChanged}
                ...
            >
            </Chart>
        );
    }

    onPointHoverChanged (e) {
        const point = e.target;
        if (point.isHovered()) {
            // Commands to execute when the point is hovered over
        } else {
            // Commands to execute when the point is hovered out
        }
    }
}

export default App;

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

JavaScript
var pointHoverChangedHandler1 = function (e) {
    var point = e.target;
    // First handler of the "pointHoverChanged" event
};

var pointHoverChangedHandler2 = function (e) {
    var point = e.target;
    // Second handler of the "pointHoverChanged" event
};

$("#chartContainer").dxChart("instance")
    .on("pointHoverChanged", pointHoverChangedHandler1)
    .on("pointHoverChanged", pointHoverChangedHandler2);
See Also