2012-07-11 42 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

相關問題