Event does not fire up in Kendo

China☆狼群 提交于 2020-01-06 17:10:13

问题


The mouse hover event does not fire up. I could not able to figure that out

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

// the following part does not fire up
var isHover = false;
$("#chart").hover(
function () {
    if (!isHover) {
        var chart = $("#chart").data().kendoChart;
        chart.options.series.data=stats2;
        isHover = true;
    }
}, function () {
    if (isHover) {
        var chart = $("#chart").data().kendoChart;
        chart.options.series.data=stats;
        isHover = false;
    }
});

http://jsfiddle.net/epvg86qu/7/


回答1:


You need to learn to debug sometimes bro, it wasn't the hover function not triggered but you just write a code carelessly.

The series property in chart's options is an array. Therefore you need an index to access it. Also because you are intend to change the series instead of its data, you have to call redraw method right after you change series data.

This code will work

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

Have a good day, cheers!!



来源:https://stackoverflow.com/questions/30172175/event-does-not-fire-up-in-kendo

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