Mouse Hover or Click Event in Line Chart

試著忘記壹切 提交于 2019-12-25 16:39:35

问题


When user hovers the mouse on the #chart, then second data is drawn.

However I would like to know when user hovers the mouse on the first data line by itself not #chart then second data line is drawn.

function createChart() {
    $("#chart")
        .kendoChart({
            xAxis: {},
            yAxis: {},
            seriesDefaults: {type: "scatterLine" },
            series: [{data: stats2},{name:"gmail"}],
  })
}

var isHover = false;
$("#chart").hover(
    function () {
    if (!isHover) {
        var chart = $("#chart").data().kendoChart;
        chart.options.series[0].data = stats2;
        chart.options.series[0].name="yahoo";
        chart.redraw();
        isHover = true;
    }
}, function () {
    if (isHover) {
        var chart = $("#chart").data().kendoChart;
        chart.options.series[0].data = stats;
        chart.options.series[0].name="";
        chart.redraw();
        isHover = false;
    }
});

http://jsfiddle.net/epvg86qu/12/


回答1:


Add this within createChart (and replace the function with your desired behavior). This example just writes "hello" to the console.

function createChart() {
    $("#chart")
        .kendoChart({
            xAxis: {},
            yAxis: {},
            seriesDefaults: {type: "scatterLine" },
            series: [{data: stats2},{name:"gmail"}],
            seriesHover: function(e) {
                console.log("hello");
            }
        })
}


来源:https://stackoverflow.com/questions/30173359/mouse-hover-or-click-event-in-line-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!