Drawing multiple lines with IE7

54 views
Skip to first unread message

Sean

unread,
Apr 24, 2009, 3:19:57 PM4/24/09
to plotkit
I've been developing a project using PlotKit. I want to be able to
draw a single graph with multiple lines of different colors. Here's
how I've been doing it:

var Color = MichiKit.Color.Color;
var layout = new PlotKit.Layout("line", {});
layout.addDataset("1", [...]);
layout.evaluate();
var params = { shouldFill: false, strokeColor: Color.fromName
("red") };
var plotter = new PlotKit.CanvasRenderer(canvasElement, layout,
params);
plotter.render();

var layout2 = new PlotKit.Layout("line", {});
layout2.addDataset("2", [...]);
layout2.evaluate();
var params2 = { shouldFill: false, strokeColor: Color.fromName
("green"), drawBackground: false, drawXAxis: false, drawYAxis:
false };
var plotter2 = new PlotKit.CanvasRenderer(canvasElement, layout2,
params2);
plotter2.render();

(Because I want my lines to be drawn in different colors, I can't just
add multiple datasets to a single layout object, as far as I
understand it.)

This technique works well on Firefox, but when I try it on IE7, an
exception is thrown from the innards of PlotKit on the second
CanvasRenderer instantiation: "CanvasRenderer() - <canvas> needs to be
enclosed in <div>". My canvas object was definitely originally
wrapped in a div. If I print the nodeName of my canvas object just
before instantiating that second CanvasRenderer, it's "#document-
fragment".

This is using PlotKit version 0.8, by the way.

Any ideas or alternate approaches? Thanks in advance for any help.

Per Cederberg

unread,
Apr 25, 2009, 3:18:16 AM4/25/09
to plo...@googlegroups.com
I think you can plot both in the same Canvas using a "colorScheme" instead:

var colors = [Color.fromName("red"), Color.fromName("green")];
var params = { shouldFill: false, colorScheme: colors };

Cheers,

/Per

Julien Wajsberg

unread,
Apr 25, 2009, 1:56:38 AM4/25/09
to plo...@googlegroups.com
I don't think PlotKit is still developed, you should try Flotr (http://solutoire.com/flotr/) or Flot (http://code.google.com/p/flot/) instead.

Regards,

2009/4/24 Sean <eef...@gmail.com>

Per Cederberg

unread,
Apr 25, 2009, 6:44:16 AM4/25/09
to plo...@googlegroups.com
Well, PlotKit is at least somewhat maintained:

http://github.com/cederberg/plotkit-patches/tree/master

Cheers,

/Per

Sean McAfee

unread,
Apr 25, 2009, 11:31:50 AM4/25/09
to plo...@googlegroups.com
On Fri, Apr 24, 2009 at 10:56 PM, Julien Wajsberg <fel...@gmail.com> wrote:
I don't think PlotKit is still developed, you should try Flotr (http://solutoire.com/flotr/) or Flot (http://code.google.com/p/flot/) instead.

Well, I'm maintaining an existing project that uses Plotkit, and I don't have much time to invest in evaluating alternatives, if it can be avoided.

What I ended up doing was modifying PlotKit a bit, adding a third color parameter to the addDataset method of the Layout class.  It was very easy, only about a six-line change in all.

Reply all
Reply to author
Forward
0 new messages