2011-06-14 68 views
1

jqplotを使用してページ上にグラフを描画しています。私は複数の行をプロットしており、その行を識別するのに役立つ凡例を表示する必要があります。凡例(jqplot)内の個々のラベルの色を設定する方法は?

各色の色が異なるため、凡例に表示される個々のラベルの色を設定する方法を見つける必要があります。

var plot3 = jQuery.jqplot('div1', [data1, data2, data3, data4], 
    { 
     // Series options are specified as an array of objects, one object 
     // for each series. 
     series:[ 
      { 
      color: '#FF0000', 
      // Change our line width and use a diamond shaped marker. 
      lineWidth:2, 
      markerOptions: { style:'diamond' } 
      }, 
      { 
      color: '#00FF00', 
      // Don't show a line, just show markers. 
      // Make the markers 7 pixels with an 'x' style 
      showLine:false, 
      markerOptions: { size: 7, style:"x" } 
      }, 
      { 
      color: '#0000FF', 
      // Use (open) circular markers. 
      markerOptions: { style:"circle" } 
      }, 
      { 
      color: '#F0000F', 
      // Use a thicker, 5 pixel line and 10 pixel 
      // filled square markers. 
      lineWidth:5, 
      markerOptions: { style:"filledSquare", size:10 } 
      } 
     ], 

legend:{ 
      renderer: jQuery.jqplot.EnhancedLegendRenderer, 
      show: true, 
      labels: ['data1', 'data2', 'data3', 'data4'] 
     } 
    } 

を[編集]

Iは、以前のコードを削除しました - それは赤いニシンでした。私は問題を解決しようとしている新しい方法を反映するためにタイトルを変更しました。

答えて

5

伝説の後、このようにそれを追加してください:

legend: {show: true } , 
series:[{label:'BANANA'}, {label:'ORANGE'} ], 

は、これはあなたに伝説の名を与えます。

0

次のようにseriesColorsを使用することにより、一連のや伝説上の色を設定することができます。

var plot1 = $.jqplot('chart', [data1, data2], { 
legend: { 
    show: true 
}, 
seriesColors: ['red', 'blue'] 
}); 
関連する問題