微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何为图例jqplot中的各个标签设置颜色?

如何解决如何为图例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\']
        }
    }
[编辑] 我删除了先前的代码-因为它是一条红色鲱鱼。经过数天的努力,我还更改了标题以反映解决问题的新方法。     

解决方法

        图例之后,请按以下方式添加:
legend: {show: true },series:[{label:\'BANANA\'},{label:\'ORANGE\'}  ],
这将为您提供图例名称。     ,        您可以使用
seriesColors
在系列和图例上设置颜色,如下所示:
var plot1 = $.jqplot(\'chart\',[data1,data2],{
legend: {
    show: true
},seriesColors: [\'red\',\'blue\']
});
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。