reveal search box

PlotKit - Javascript Chart Plotting

Introduction

PlotKit is a Chart and Graph Plotting Library for Javascript. It has support for HTML Canvas and also SVG via Adobe SVG Viewer and native browser support.

PlotKit is fully documented and there is a quick tutorial to get you started.

PlotKit is a complete rewrite of CanvasGraph. It is better structured and supported.

Requirements

  • MochiKit 1.3 or higher
  • HTML Canvas: Safari 2+, Opera 9+, Firefox 1.5+, IE 6 (in emulated mode)
  • SVG: Opera 9+, Firefox 1.5+ (see note), IE6 with Adobe SVG.

Note: Firefox 1.5+ on Linux and Windows is supported. Firefox 1.5+ on Mac does not draw labels in SVG, so you must set axisLabelUseDiv to true if you want to have maximum compatibility.

License(s)

  • PlotKit is copyright (c) 2006 Alastair Tse. Licensed under the BSD License.
  • excanvas.js is copyright (c) 2006. Google Inc. Licensed under the Apache License.

Get/Download

Documentation

Development

Examples

Demo

Below is a demo of a simple HTML Canvas example which should work in Safari 2, Firefox 1.5, Internet Explorer 6 and Opera 9. And SVG Demo can also be found.

This is the HTML in the above demo:

<div class="demo" id="canvaspie" width="600" height="200"></div>
<div class="demo" id="canvasline" width="600" height="200"></div>
<div class="demo" id="canvasbar" width="600" height="200"></div>

And the Javascript that is needed to draw the charts:

function demo() {
   var hasCanvas = CanvasRenderer.isSupported();

   var opts = {
   "pieRadius": 0.4
   };

   var data1 = [[0, 5], [1, 4], [2, 3], [3, 5], [4, 6], [5, 7]];
   var data2 = [[0, 2.5], [1, 2], [2, 1.5], [3, 2.5], [4, 3], [5,
   3.5]];
   var data3 = [[0, 1.25], [1, 1], [2, 0.75], [3, 1.25], [4, 1.5], [5, 1.75]];

   if (hasCanvas) {
       var pie = new EasyPlot("pie", opts, $('canvaspie'), [data1]);
       var line = new EasyPlot("line", opts, $('canvasline'), [data1, data2, data3]);
       var bar = new EasyPlot("bar", opts, $('canvasbar'), [data1, data2, data3]);
   }
}

Screenshot

If you do not see the above, this is what you should have seen:

PlotKit Screenshot

About

PlotKit was created by: Alastair Tse - alastair@liquidx.net

add commentAdd a comment
neva says
50
Great library! I just started using it and so far really enjoy it.
  • 1 week, 5 days ago (12/07/2008)
Alex says
49
Is there any code difference between the kit downloaded and the one on your site?
  • 1 week, 5 days ago (12/07/2008)
Web Design Glasgow says
48
Fantastic - thanks for making these publicly available and for providing great documentation!
  • 3 months, 2 weeks ago (10/04/2008)
mike says
47
The examples are the kind of very low quality plots I would expect from limited utility spreadsheet programs such as excel.
Can it draw detailed plots too?
  • 3 months, 3 weeks ago (28/03/2008)
kenoko says
46
Very nice stuff
  • 5 months ago (23/02/2008)
Max says
45
I created a www.web2py.com helper to use PlotKit. You can find it in the PlotKit appliance at http://mdp.cti.depaul.edu/appliances
  • 5 months, 3 weeks ago (29/01/2008)
January Autumn says
44
I've downloaded. But the demo can't run. Pls help me.
  • 6 months ago (21/01/2008)
Massimo says
43
Anybody interested in helping make a Gluon (http://mdp.cti,depaul.edu) module for plotkit?
  • 7 months, 3 weeks ago (05/12/2007)
Santosh says
42
In safari in line chart line are not colored, Can any one guide me on this regard ?
  • 8 months ago (22/11/2007)
Sebastian says
41
Hi there !
Plotkit dev team has any plan to make it support negatives? This is a show stopper to me. Well I see those good looking bars and I imagine making a cashflow with them but can't make it because it starts from negatives to positives.
I would love to see plotkit achieving that.
  • 8 months, 1 week ago (15/11/2007)
santosh pandey says
40
I m trying to create a line graph with points, can someone please point me in the right direction ?
  • 8 months, 1 week ago (14/11/2007)
Bobby says
39
Is there any way to feed the data into a pie chart through an excel sheet? please help me ..its very urgent
thanx in advance
  • 9 months, 1 week ago (19/10/2007)
Oli says
38
Is there anyway a hyperlink can be embedded into the dataset display - so a bar...or other charting element can be click and querystring paramaters passed to a page...and pseudo drill-down I suppose?
  • 9 months, 2 weeks ago (12/10/2007)
Himen says
37
Hi,
I could figure out the problems i faces below. Thanks for providing the library.
I know the tutorial says that lib does not support negative no, but when i plotted a line graph with negative values the result was correct on Mozilla but on IE the display of the no was not proper. Please let me know if you have some solutions for this
  • 10 months, 1 week ago (17/09/2007)
Himen says
36
Hi, I am trying to create a line graph using this library and by default the graph starts from "0". I tried to use xOriginIsZero = false in my options but it still starts from 0 on X-axis. Please let me know the correct way of doing it. Also is there any way i could remove the line which the graph creates at from the last point to the X-axis.

Thanks
  • 10 months, 1 week ago (14/09/2007)
zulyo says
35
for jack include the source refer of excanvas.js ( )
  • 10 months, 3 weeks ago (04/09/2007)
jack says
34
Hi, first of all, thanks to the great codes! I am trying my web application under IE, but it failed, so i will appreciate it if you give me some suggestions.

I copy the example in quick-start and my graphic options are:

var gOptions = { drawYAxis: false, pieRadius: 0.4, drawBackground: false, axisLabelFontSize: 11, IECanvasHTC: "/javascripts/plotkit/iecanvas.htc" };

Under IE, it tells me "G_vmlCanvasManager is undefined", so what should i do next?

Thanks
  • 10 months, 3 weeks ago (01/09/2007)
Tim says
33
Thanks for this great library!!
  • 11 months ago (24/08/2007)
Weijia says
32
On my local, the example kit only runs with IE, not with FireFox. The fireFox version is 2.0.0.6. But I can run the example on the http://www.liquidx.net/plotkit/ with FireFox.

Is there any code difference between the kit downloaded and the one on your site?

Thanks,
Weijia
  • 11 months, 2 weeks ago (08/08/2007)
Prasanna says
31
Hi,

Is it possible to use plotkit to plot a live graph or a moving graph.

See "the performace tab" under the windows task manager.

Thanks
Prasanna
  • 11 months, 2 weeks ago (08/08/2007)
Go Green! says
30
Hello,

Excellent tool but anyone knows how to round the decimals? Having a whole number values on the y-axis.
  • 12 months ago (26/07/2007)
Dmitry says
29
Hi,
Thanks for great script.
For my purpose, I add next feature to this script:
1) 'only line' chart
2) legend box
3) few functions for table parsing.
You can find my example with this link
http://dimon372.narod.ru/plotkit/example.html

Maybe, somebody will find it useful.

best regards, Dmitry
  • 1 year ago (13/07/2007)
tom says
28
mmh, thanks, but I don't find the position and the syntax where I can put it in. Can you give me an example please?

I call the chart with this code:

var options = {
"xTicks": [{v:1, label:"Open"},
{v:2, label:"Close"},
{v:3, label:"Error"}],
"drawYAxis": false
};
var layout = new Layout("pie", options);
layout.addDatasetFromTable("dataset", $("values"), xcol = 0, ycol = 1);
layout.evaluate();
var chart = new SweetCanvasRenderer($("chart"), layout);
chart.render();
  • 1 year ago (13/07/2007)
Alastair Tse says
27
Yes, you definitely can. You just have to pass it an array of MochiKit.Color.Color with your desired colors as the "colorScheme" option to the renderer.

For more information, you should read the PlotKit Renderer docs
  • 1 year ago (13/07/2007)
tom says
26
hey,

can I set up colors for every pie slice?
I want to have red, yellow and green for the first three values. Please help me :-)
  • 1 year ago (12/07/2007)
arikan says
25
Thanks for building this much need library.

At first Plotkit did not work in Ruby on Rails, then I resovled by doing these two things:

1. In MochiKit.js I changed /MochiKit.js$/ to /MochiKit.js/. Removing the $ sign worked because Rails adds id numbers at the end of Javascript files to keep them in cache.

2. I removed scriptaculous.js. It seems like these libs are conflicting somehow.

  • 1 year ago (25/06/2007)
David says
24
SVG charts also work with Safari 3.0 now.
  • 1 year, 1 month ago (17/06/2007)
Don says
23
Great script. Thanks for writing this. I just wanted to point something out in case other people were having the same problem. If you're trying to display multiple charts on the same page with the CanvasRenderer, you need to make sure that all of the divs you use have both an open and close element (like ) even if there's nothing in them, otherwise PlotKit won't be able to draw the second chart. I had an empty div I was putting a legend in using the other legend js I found linked to from this site.

-- Don
  • 1 year, 1 month ago (16/06/2007)
Alastair Tse says
22
@Christian: Thanks, I've added your fix to the latest SVN version in ChangeSet 68

@gacopys: Thank you too, although I didn't quite understand what you did to fix it, but the diff is in changeset 69 in SVN.
  • 1 year, 1 month ago (11/06/2007)
Christian says
21
Alastair,

If you ever get around to releasing another version of PlotKit, there are two instances (Base.js line 303-304) where the MochiKit Color library is referenced via the global Color class (ie Color.grayColor() instead of MochiKit.Color.Color.grayColor()) that you might want to fix. When I turned off exporting of MochiKit variables, these two lines threw errors. Also, the version number needs to be updated in the packed version from .8 to .91. Thanks.
  • 1 year, 1 month ago (11/06/2007)
gacopys says
20
I've managed to fix problem with hitTest(x,y) on pie graph. There were problems with calculating angles and x variable. Here is the link to changed script.

http://gacopys.tivi.net.pl/rozne/PlotKit_Packed.js
  • 1 year, 1 month ago (11/06/2007)
nasir says
19
can I set up colors for every pie slice?
  • 1 year, 1 month ago (11/06/2007)
vip says
18
Would be great having style for labels (on x and y axis) or an option for vertical labels (if xTicks are longer than bar width).
  • 1 year, 1 month ago (31/05/2007)
denver web designer says
17
We've been looking for a tool such as this which would make our metrics appear more Google Analytics like. Thank you!
  • 1 year, 1 month ago (29/05/2007)
Christian Effenberger says
16
Hi,

I’ve extended the features of S5 1.3 (aka Reloaded) with dynamically generated, scalable pie charts in canvas objects through parsing html tables. I needed text for the percentage strings (0123456789%.).

I’ve tested html-, image- and stroke-text.

The implementation of vector fonts is the wrong way because of the complexity. But integrating the very simple stroke fonts from CAD programs is much more interesting.

Here is the sample link:

http://www.netzgesta.de/S5/canvas-text.html
  • 1 year, 3 months ago (04/04/2007)
Nathaniel Domingo says
15
http://nieldomingo.blogspot.com/2007/03/legend-for-plotkit-bar-charts.html

check out my blog post on plotkit. its all about making a legend for plotkit.
  • 1 year, 3 months ago (31/03/2007)
Dave says
14
Great script!

However, when I tried to get Integers in a barchart y-axis (through yTickPrecision: 1 or 0, or anything else) it does not seem to have the desired effect. I want integers for my y-axis (when they represent say a "person": 1 person, not 1.2 person :-) )

Is this possible?
  • 1 year, 3 months ago (30/03/2007)
Jeremy Suriel says
13
missing the following line in the function _evaluatePieCharts in file layout.js, around line 531...

var map = MochiKit.Base.map;

caused ie to have problems displaying pie charts sometimes...not sure why it worked others...now it works all the time
  • 1 year, 3 months ago (28/03/2007)
Neumi says
12
HEY!
Great and useful Script! Thanks a lot!!!!!
  • 1 year, 3 months ago (28/03/2007)
Nathaniel C. Domingo says
11
You might be interested in my blog posts concerning my use of plotkit:

http://nieldomingo.blogspot.com/2007/03/fix-for-working-with-plone-mochikit-and.html
http://nieldomingo.blogspot.com/2007/03/improved-tick-marks-for-plotkit.html
http://nieldomingo.blogspot.com/2007/03/different-rendering-for-negative-values.html

I am still preparing another blog post on Plotkit. I'll post the link here once I'm done.

Thanks and hope you find my posts helpful.
  • 1 year, 4 months ago (26/03/2007)
Paul says
10
Great script ... but why do the pie charts print out so small?
  • 1 year, 4 months ago (12/03/2007)
Alexey Babak says
9
what a great script
thanks
  • 1 year, 4 months ago (12/03/2007)
Rick Sarvas says
8
I have to admit that after looking through the Plotkit JS code I'm a bit confused as to how to define custom color schemes for charts (using MochiKit?). Part of this is that I'm still new to JavaScript, though, some sort of color manipulation example would be helpful.
  • 1 year, 4 months ago (08/03/2007)
Silvester says
7
How about a sparkline type of graph as seen here http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001OR&topic_id=1

(Edward Tufte Sparklines)
  • 1 year, 4 months ago (08/03/2007)
Pau says
6
Hi ,
I need to make big charts with large amounts of values (3000 - 4000 aprox). Do you know if this charts can make it ? I tried with some flash components and they crash because the XML size.

Thnk's in advance.
  • 1 year, 5 months ago (30/01/2007)
Qureshi says
5
I know the forum is the right place to ask such things but i did not find the solution there very useful
When i try to draw horizontal bar charts the labels cut-off
even by changing the padding , the labels always start from the edge of the chart and remain cut
  • 1 year, 7 months ago (13/12/2006)
plusgoals says
4
Great library! I just started using it and so far really enjoy it.

Quick note for those of you using this with a Rails app. To get it to work you need to change the regexp /MochiKit.js$/ to /MochiKit.js/ in MochiKit.js . Rails puts a bunch of extra numbers at the end of css and js files when they are included (I believe for caching).

Thank you for this.
  • 1 year, 8 months ago (26/11/2006)
Tom says
3
Hi,


Great tool and easy to use. I was wondering is there any way I could get these charts to pdf?
  • 1 year, 8 months ago (07/11/2006)
Jaset says
2
I could not get this stuff run with Scriptaculous Libraries included in the head.
I wanna use visual effects from this library and this graph library. Couldnt get it to work. Always threw error messages at me on all browsers. When I removed Scriptaculous libs it worked immediately. ;((
  • 1 year, 9 months ago (09/10/2006)
Prem says
1
I added a line only chart without fill, if you think this is good would you please add it to the new releases, I have to modify my source code everytime I download the new releases to include my line only chart.
Thanks
Prem

Heres the thread where i posted the code

http://groups.google.com/group/plotkit/browse_thread/thread/4d43f351a893d694

Thanks again
  • 1 year, 11 months ago (16/08/2006)
Older comments may be hidden from this page ..