I am exploring flot, the jquery graphing library.
I'd like to be able to create a bar chart. Seems like it was not really set up for this. If I contort my data a little, I can get it to mostly do what I envision. Using this code:
var dataSet = [
[ 15132, "Inez" ],
[ 21441, "Rocky" ],
[ 29141, "Jim" ],
[ 18211, "Sophia" ],
[ 17556, "Perry" ],
[ 32251, "Jorge" ],
[ 43560, "Madison" ],
[ 20180, "Gil" ],
[ 12180, "Fran" ],
[ 31018, "Sheila" ],
[ 45143, "Nial" ],
];
function plotChart() {
var d1, xaxisLabels = [], i=0;
d1 = dataSet.map(function(elt){return {label: elt[1], data: [[i++, elt[0]]]};});
i = 0;
// example for xaxis option: {ticks: [[1,'One'], [2,'Two'], [3,'Three'], [4,'Four'], [5,'Five']]},
xaxisLabels = dataSet.map(function(elt) { return [i++, elt[1]]; });
$.plot($("#chart1"),
d1,
{
legend: {
show: true,
container: $('#legend1'),
},
series: {
bars: {
show : true,
align : 'center',
//dataLabels : true,
barWidth : 0.4
}
},
xaxis: { ticks: xaxisLabels },
yaxis: {
ticks: 10
},
grid: {
show: true,
backgroundColor: { colors: ["#fff", "#eee"] }
}
});
}
$(document).ready(plotChart);
This is what I get:
That's pretty good. But I'd like to remove the vertical axis lines. These might make sense in a line chart, but not in a bar chart.
Anyone know how I can do that?
All you need is
xaxis: { tickLength: 0 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With