jQuery flot插件,情节和标签顺序

时间:2012-07-23 09:31:45

标签: jquery flot

http://code.google.com/p/flot/

默认情况下,绘图和标签按顺序显示,我定义了它们

$.plot($("#chart"),
                        plotData
                    ,
                    {
                        series:{
                        lines:{ show:true },
                        points:{ show:true }
                        },
                        grid:{ hoverable:true, clickable:true },
                        yaxis:{ min:0, max:data.maxYaxisValue, tickDecimals:0},
                        xaxis:{ tickFormatter:tickFormatter}
                    }
                );

plotdata是一个数组,结构为:

var plotData = [
 {data: statData1,  color: plotColor1, label: label1},
 {data: statData2,  color: plotColor2, label: label2},
 {data: statData3,  color: plotColor3, label: label3}
];

我想要一个订单中的显示图,另一个订单中的标签:

图:

plot1 plot2 plot3

图例表:

plot3 plot1 plot2

我只有一个想法:通过脚本更改图例表中的顺序,我不会在此处看到此选项

  if ($('#chart div.legend table tr').length > 1) {
                var $tableRow = $('#chart div.legend table tr:last');
                $tableRow.insertBefore($('#chart div.legend table tr:first'));
            }

还有更好的方法吗?

1 个答案:

答案 0 :(得分:3)

Github上的Flot master分支支持独立于其系列排序图例标签。

它刚刚在一周前添加,所以如果你已经在使用主分支,你可能只需要更新。如果您使用的是0.7,则可以切换到主分支,如果您可以更不稳定,或者在历史记录中找到这些特定提交并将其手动应用到您的副本中。