Reputation: 5737
I see how to display barcharts in flot with horizontal bars, or vertical bars, which can be "stacked" vertically, but I can't find examples of how to display barcharts that are horizontal AND stacked.
How would I do this?
Here's the code I have, copied from the poster below's site, but still the bars won't stack
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="flot/jquery.flot.js"></script>
<script type="text/javascript" src="flot/jquery.flot.stack.js"></script>
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i <= 10; i += 1)
d1.push([parseInt(Math.random() * 30),i]);
var d2 = [];
for (var i = 0; i <= 10; i += 1)
d2.push([parseInt(Math.random() * 30),i]);
var d3 = [];
for (var i = 0; i <= 10; i += 1)
d3.push([parseInt(Math.random() * 30),i]);
$.plot($("#placeholder"), [ d1, d2, d3 ], { series: {
stack: true,
lines: { show:false },
bars: { show: true, barWidth: 0.6, horizontal:true } } });
});
</script>
<title>Test</title>
</head>
<body>
<div id="placeholder" style="width:600px;height:300px;"></div>
</body>
</html>
Upvotes: 4
Views: 5826
Reputation: 21226
Just specify both stack:true
and in your bars definition horizontal:true
, that should be it...
$.plot($("#placeholder"), data, {
series: {
stack: true,
lines: { show:false },
bars: { show: true, barWidth: 0.6, horizontal:true }
}
});
See it working here: http://jsfiddle.net/ryleyb/wt6aJ/
Upvotes: 6