How to set the colors for individual labels in a legend (jqplot)?
I am using jqplot to plot a chart on a page. I am plotting multiple lines and I need to display a legend which will help identify the lines.
The lines have different colors, so I need to find a way of setting the coklor of individual labels displayed in the legend.
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:"filled开发者_运维问答Square", size:10 }
}
],
legend:{
renderer: jQuery.jqplot.EnhancedLegendRenderer,
show: true,
labels: ['data1', 'data2', 'data3', 'data4']
}
}
[Edit]
I have removed the previous code - as it was a red herring. I have also changed the title to reflect the new way I am trying to solve the problem, after struggling with it for days.
After legend, please add it like this:
legend: {show: true } ,
series:[{label:'BANANA'}, {label:'ORANGE'} ],
This will give you legend name.
You can set the color on the series and on the legend by using seriesColors
as follows:
var plot1 = $.jqplot('chart', [data1, data2], {
legend: {
show: true
},
seriesColors: ['red', 'blue']
});
精彩评论