Javascript 如何设置图例(jqplot)中单个标签的颜色?

Javascript 如何设置图例(jqplot)中单个标签的颜色?,javascript,jquery,jqplot,Javascript,Jquery,Jqplot,我使用jqplot在页面上绘制图表。我正在绘制多条线,我需要显示一个图例来帮助识别这些线 线条有不同的颜色,所以我需要找到一种方法来设置图例中显示的各个标签的颜色 var plot3 = jQuery.jqplot('div1', [data1, data2, data3, data4], { // Series options are specified as an array of objects, one object // for each serie

我使用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']
        }
    }
[编辑]


我已经删除了前面的代码——因为这是一个骗局。我还更改了标题,以反映我在与之斗争了几天之后试图解决问题的新方法。

在图例之后,请添加如下内容:

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

这将为您提供图例名称。

在图例之后,请按如下方式添加:

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

这将为您提供图例名称。

您可以使用
系列颜色设置系列和图例的颜色,如下所示:

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

您可以使用
seriesColors
设置序列和图例上的颜色,如下所示:

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