通过单击浮动图表中的图例来切换数据系列? [英] Toggle data series by clicking legend in flot chart?
问题描述
我已经使用flot.js绘制了一些数据,但是我有很多数据系列,因此用户可能希望隐藏一些系列. flot的示例之一显示了如何通过使用复选框来切换数据序列.我想单击图例的小颜色框或标签,以切换该系列的可见性.有可能吗?
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 toggle data series by using checkboxes. I would like to make clicking the legend's little color box or the label, to toggle the visibility of that series. Is that possible?
推荐答案
以下是使用复选框可以对其进行修改以在每个legendLabel上放置一个click事件,但是您一次只能显示一个图例.
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.
在ready函数中使用类似的内容
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 }
});
}
);
这篇关于通过单击浮动图表中的图例来切换数据系列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!