2012-07-11 45 views
2

我有一个填充了六个数据系列的矩阵,我想用同一个名称“process a”标记前五个(也给它们相同的颜色),而左边的是'process b'。那么有没有办法在jqplot中做到这一点?感谢您的任何建议。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' 
      } 
     }) 
    })​ 

回答

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(); 
+0

感谢您的帮助。这与我想要的非常接近。但是,是否有可能仅显示两个图例(过程A和B)而不是全部六个(过程A和过程B)?另外,是否可以使用循环来分配这些系列信息(使用'push'来添加标签名称和颜色)? – 2012-07-12 14:23:51

+0

有关您的答案,请参阅**编辑**。 – Boro 2012-07-12 14:46:29

+0

有一种更简单的方法来修复图例中的多个条目。对于系列配置,为每个附加重复添加“showLabel:false”。例如: ''系列:[' ''标签:'处理A',颜色:'红'},{标签:'处理A',颜色:'红',showLabel:false}' ''' – 2017-01-05 15:27:21

相关问题