jqplot分组并标记具有相同名称和颜色的多个数据系列

时间:2012-07-11 18:38:41

标签: javascript jquery jqplot

我有一个填充了六个数据系列的矩阵,我想在其中标记前五个同名的'处理一个' (也给他们相同的颜色),左边的一个用'处理b'。那么在jqplot中有没有办法做到这一点?感谢您的任何建议。

以下是代码和demo

$(document).ready(function(){
        $.jqplot.config.enablePlugins = true;

        s1 = [[10.0, 11.0, 11.0, 12.0, 12.0, 14.0], [10.0, 11.0, 12.0, 12.0, 12.0, 12.0], [10.0, 13.0, 14.0, 15.0, 15.0, 16.0], [10.0, 10.0, 11.0, 11.0, 11.0, 12.0], [10.0, 10.0, 11.0, 12.0, 12.0, 12.0]];
        s2 = [10.0, 10.4, 10.816, 11.248640000000002, 11.698585600000003, 12.166529024000004];

        s1.push(s2);
        $.jqplot('chart1', s1, {

            seriesDefaults: { 
            showMarker:false,
             pointLabels: { show:false } ,
              },

            series:[
            {label:'Process A'},{label:'Process B'}
            ],

             legend: {
                  show: true,
                  location: 'nw',
                  placement: 'inside',
                fontSize: '11px'
            } 
        })   
    })​

1 个答案:

答案 0 :(得分:2)

是的,有办法。 I think this is what you want. 你已经走在了正确的轨道上。您只需相应地重复设置每个系列的标签和颜色,如代码示例或下面所示:

series:[
  {label:'Process A', color: 'red'}, {label:'Process A', color: 'red'}, {label:'Process A', color: 'red'}, {label:'Process A', color: 'red'}, {label:'Process A', color: 'red'}, {label:'Process B',color:'blue'}
]

修改

This is the answer where I show how to manipulate the legend.

另请查找此示例,扩展其他答案的代码。 The sample shows how to hide legend with index 1.基本上您使用jQuery方法hide()抓取样本和标签并隐藏它们:

var swatches = $('table.jqplot-table-legend tr td.jqplot-table-legend-swatch');
var labels = $('table.jqplot-table-legend tr td.jqplot-table-legend-label');
$(swatches[1]).hide();
$(labels[1]).hide();