Stacked graph and non-stacked line on same plot

1,271 views
Skip to first unread message

Peter Baumgartner

unread,
May 6, 2011, 2:00:12 PM5/6/11
to Flot graphs
I'd like to setup a stacked bar graph with a simple line graph
overlayed on the same plot. Is this possible? If so, what would the
syntax look like for the arguments to $.plot? I've tried a few
combinations, but am not having any luck.

Thanks in advance for any insight!

-- Pete

Michael Wood

unread,
May 6, 2011, 3:33:03 PM5/6/11
to flot-...@googlegroups.com

Michael Wood

unread,
May 6, 2011, 3:52:14 PM5/6/11
to flot-...@googlegroups.com

Sorry, I missed the "stacked bar graph" part of your message
initially. I don't know if that can work. The line would have to be
excluded from the stacking somehow, I suppose.

--
Michael Wood <esio...@gmail.com>

Michael Wood

unread,
May 6, 2011, 3:55:17 PM5/6/11
to flot-...@googlegroups.com

OK, got it. You just override the stack: true with stack: null in the
series for the line:

$(function () {
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];

var d4 = [];
for (var i = 0; i < 14; i += 0.1)
d4.push([i, Math.sqrt(i * 10)]);

var d5 = [];
for (var i = 0; i < 14; i += 1)
d5.push([i, Math.sqrt(i)]);

$.plot($("#placeholder"), [
{
data: d2,
bars: { show: true }
},
{
data: d4,
lines: { show: true },
stack: null
},
{
data: d5,
bars: { show: true },
}
], { series: { stack: true } });
});

--
Michael Wood <esio...@gmail.com>

Reply all
Reply to author
Forward
0 new messages