I've been using Flot charts for a short period of time and I need to display a bar chart with one or two series depending on the selection:
if (lC2 != 'None') {
values = [
{ label: lC1, data: arrC1, color: cC1 },
{ label: lC2, data: arrC2, color: cC2 }
];
bWidth = 0.15;
}
else {
values = [{ data: arrC1, color: cC1 }];
bWidth = 0.3;
}
and my function that draws the chart is:
function BarChartH(id, data, ticksl) {
$.plot(id, data, {
series:{
bars: {
show: true,
barWidth: bWidth,
order: 1,
horizontal: true
}
},
grid: {
hoverable: true
, align: "center"
//,horizontal: true
},
legend: {
show: true
}
, yaxis: { ticks: ticksl }
});
}
But when it needs to display both series (lC2 != 'None'
) it appears only the second one (the bars become stacked).
The thing is that if I remove 'order:1' from the function and add the order for each data like:
values.push({ label: lC1, bars: { order:1 }, data: arrC1, color: cC1 });
values.push({ label: lC2, bars: { order:2 }, data: arrC2, color: cC2 });
OR
values = [
{ label: lC1, bars: { order:1 }, data: arrC1, color: cC1 },
{ label: lC2, bars: { order:2 }, data: arrC2, color: cC2 }];
it displays both of the series but with a lot of space between the bars and when there are many they overlap (the lC2 bar from the first Y label overlaps with the lC1 bar from the second Y label like in the attached image).
I need to get both the bars of the same Y label closer to make a difference between them, but I don't know what am I doing wrong.
EDIT: Added: fiddle