0

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/

casillas
  • 16,351
  • 19
  • 115
  • 215

1 Answers1

2

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!!

Dion Dirza
  • 2,575
  • 2
  • 17
  • 21
  • it is awesome! thank a lot again bro! By the way, I have looked for debugging in jsfiddle, but it is somehow limited, it does not show me js source code. – casillas May 11 '15 at 16:26