Flot删除数据集

时间:2013-12-20 04:56:45

标签: flot

这是我在点击数据点时删除数据点的方法:

item.series.data[item.dataIndex].shift()
item.series.data[item.dataIndex].shift()

是什么代码删除数据点所属的整个系列?

1 个答案:

答案 0 :(得分:2)

我猜你是从plotclick处理程序执行此操作:

$("#placeholder").bind("plotclick", function (event, pos, item) {
    if (item){
        var someData = plot.getData(); //get the series array
        someData.splice(item.seriesIndex,1); //remove the index of the one clicked
        plot.setData(someData); //set the data
        plot.setupGrid();
        plot.draw();  //redraw
    }        
});

工作小提琴here

评论的编辑

更新了小提琴here,根据系列名称而不是索引位置从多个图表中删除。

$(".chart").bind("plotclick", function (event, pos, item) {
    if (item){
        var label = item.series.label;
        $([plot1, plot2]).each(function(i,plotObj){
            var someData = plotObj.getData();
            for (var i=0; i<someData.length; i++){
                if (someData[i].label == label){
                    someData.splice(i,1);
                }                
            }
            plotObj.setData(someData);
            plotObj.setupGrid();
            plotObj.draw();                
        });
    }        
});