Toggle data series by clicking legend in flot chart?

后端 未结 2 1349
忘掉有多难
忘掉有多难 2021-02-09 19:01

I have played a bit with flot.js for plotting some data, but I have quite a few data series, so the user might want to hide some series. One of flot\'s examples shows how to tog

2条回答
  •  你的背包
    2021-02-09 19:28

    Here is an example that uses checkboxes http://people.iola.dk/olau/flot/examples/turning-series.html

    It could be modified to place a click event on each legendLabel, but you would only be able to show one legend at a time.

    using something like this in the ready function

    
    $('.legendLabel').click(
    function(d){
        var country = $(this).html().toLowerCase();
              var data = [  ];
        //alert( country );
        data.push( datasets[country] );
    
            if (data.length > 0)
                $.plot($("#placeholder"), data, {
                    yaxis: { min: 0 },
                    xaxis: { tickDecimals: 0 }
               }); 
    
    }
    ); 

提交回复
热议问题