Search code examples
jqueryjquery-eventsjqplot

Event handler making jqplot crash


I followed one of the examples given on jqplot official web page for event handler. Basically I'd like to display the different series when a checkbox is ticked.

I use the following event handler:

    $("input.dataSeries-checkbox").attr("checked", false);
$("input.dataSeries-checkbox").change(function(){ 

    plot1.series[1].show = false;
    plot1.series[2].show = false;
    plot1.series[3].show = false;

    if ($('input[name='VSNF']').get(0).checked === true) {
        plot1.series[1].show = true;
    }

    if ($('input[name='ISNF']').get(0).checked === true) {
        plot1.series[2].show = true;
    }

    if ($('input[name='RSNF']').get(0).checked === true) {
        plot1.series[3].show = true;
    }
    plot1.replot();
});
});

after defining the overlays which makes the whole plot crash. I checked that the event handler was the thing making the script crash (other than that all is working well and I checked that every bracket,parenthesis... was duly closed before end of the script). Any idea what makes the script crash in this ? Note I also added the associated checkboxes in the following html part with:

<li><input class="dataSeries-checkbox" type='checkbox' name='USNF'>U Filter</li>
<li><input class="dataSeries-checkbox" type='checkbox' name='BSNF'>B Filter</li>
<li><input class="dataSeries-checkbox" type='checkbox' name='VSNF'>V Filter</li>
<li><input class="dataSeries-checkbox" type='checkbox' name='RSNF'>R Filter</li>
<li><input class="dataSeries-checkbox" type='checkbox' name='ISNF'>I Filter</li>

Solution

  • I eventually managed to get rid of the issue by remodeling the event handlers in a more straigthforward way :

     $("input[type=checkbox][name='VSNF']").change(function(){
        plot1.series[1].show = this.checked;
        plot1.replot();
    });
    

    and using more simple checkboxes:

    <li><input type='checkbox' name='VSNF'>V Filter</li>
    

    Hoping this would help someon with similar issues.