I am new to jQuery flot plugin and I want to set each bar's color based on its score.
For the score of the "Myself" bar:
- 0 - 20: red
- 20 - 70: yellow
- 70 - 100: green
For the score of the "You" bar:
- 0 - 20: blue
- 20 - 70: black
- 70 - 100: orange
Code Snippet:
$.plot(
$("#placeholder"),[{
data: [[1, 81], [3.5, 33]],
label: 'Myself',
bars: {
show: true,
barWidth: 1,
lineWidth: 0,
fill: true,
fillColor: {
colors: [{brightness: 1}, {brightness: 0.5}],
horizontal: true
},
align: "center"
}
},{
data: [[2, 18], [4.5, 75]],
label: 'You',
color: 'red',
bars: {
show: true,
barWidth: 1,
lineWidth: 0,
fill: true,
fillColor: {
colors: [{brightness: 1}, {brightness: 0.5}],
horizontal: true
},
align: "center"
}
}],{
xaxis: {
ticks: [[1.5, '1st half'], [4, '2nd half']],
min: 0,
max: 5.5,
tickLength: 0
},
yaxis: {tickLength: 0},
grid: {
backgroundColor: "#ffffff",
borderWidth: 0,
markings: [{xaxis: {from: 0, to: 0}, color: "#909090"}, {yaxis: {from: 0, to: 0}, color: "#909090"}]
},
legend: {backgroundOpacity: 0.6, position: 'ne', margin: [-10, 0]},
valueLabels: {show: true, truncateValue: 2}
});
A JSFiddle of the above code is here. I really appreciate your help.