Categories   MindTouch|Tutorial

Google Charts and Graphs

13 Comments »

I am going to start posting tutorials and tips on our blog for your benefit of upcoming features for Deki Wiki 1.8.3.

The tutorial today is about the Google Charts and Graphs Deki Wiki extension.

Google Charts and graphs allow you to take comma separated values and display them in a variety of different ways.

Line Chart

The Line Chart script allows you to insert values into the following script to have a line chart display on your page:
{{ google.linechart( … ) }}

The line chart has the following values that can be changed:

  1. Width and height ex: 400, 200
  2. Chart values – This is the dataset that you want to plot on the chart ex: [[10,20,30,50,40],[40,50,30,20,10]]
  3. Legends (optional) – This is what you can name the data sets ex: ['fake','real']
  4. Colors (optional) – These are the colors of the lines ex: [ 'ff0000', '0000ff' ]

Here are the above example values inserted into the script.

{{ google.linechart(400, 200, [ [ 10, 20, 30, 50, 40 ], [ 40, 50, 30, 20, 10 ] ], [ 'fake', 'real' ], [ 'ff0000', '0000ff' ]) }}

This is what it looks like:

Google Line Chart

Bar Charts

If you want your data to be displayed as a bar chart then we will swap out the linechart in the beginning of the script with barchart

Also you can toggle with the horizonal/vertical aspect of the chart along with if the bars are next to each other or stacked using true and false values.

true,true = Vertical and stacked
true,false = Vertical and next to each other
false, true = Horizontal and stacked
false, false = Horizontal and next to each other

Here are examples of the barchart scripts with sample images below.

{{ google.barchart(400, 200, [ [ 10, 20, 30, 50, 40 ], [ 40, 50, 30, 20, 10 ] ], [ 'fake', 'real' ], [ 'ff0000', '0000ff' ], true, false) }}

Bar Chart - 2

{{ google.barchart(400, 200, [ [ 10, 20, 30, 50, 40 ], [ 40, 50, 30, 20, 10 ] ], [ 'fake', 'real' ], [ 'ff0000', '0000ff' ], false, true) }}

Bar Chart - 3

Pie Charts

Piecharts are a little different because it only requires one dataset and the last parameter is a boolean: True means that the pie chart will display in 3D and False means it will be displayed in 2D. Here are the values that are different:

labels (optional) – This is the same as Legend in Line and Bar chart ex: [ 'you', 'him', 'me' ]
colors (optional) – These are the colors of the lines (I use _ to keep the default colors)
threed (optional) – draw 3D chart default: true

Below are sample scripts with sample images below them.

{{ google.piechart(400, 200, [ 10, 20, 30 ], [ 'you', 'him', 'me' ], _, true) }}

Pie Chart 3d

{{ google.piechart(400, 200, [ 10, 20, 30 ], [ 'you', 'him', 'me' ], _, false) }}

2d Pie Chart

The Google Charts integration allows you to create pages that include dynamic charts that pertain to the content on the page, allowing you to create professional looking wiki pages for projects or presentations. Deki Wiki has numerous extensions that allow you to create dynamic pages that improve the visual appearance of your content. Let me know what other extensions you would like to see samples for.

By Corey Ganser on December 11th, 2007

13 Responses to “Google Charts and Graphs”

  1. Aart-Jan Says:

    Awesome!
    But is it necessary to develop deki script for an API that is URL encoded?

  2. Steve Bjorg Says:

    You’re correct that Google charts are just URIs. So technically you can insert them using our image dialog. However, building the correct URIs can be tricky. For instance, the URI for the 3D piechart looks like this:
    http://chart.apis.google.com/chart?chs=400×200&cht=p3&chd=t:33.33,66.67,100&chl=you+%7chim%7cme

    I would argue that the dekiscript equivalent is more readable and easier to change when needed than the raw URI, wouldn’t you?

  3. Roebot Says:

    We should give an example here that is a mashup of something with the Google Charts and Graphs.

  4. Aaron Fulkerson Says:

    We should give an example of a mashup with Google Charts and Graphs.

  5. Petrus4 Says:

    Nice! hmm.. can this extension also be used to pull data from a database table or spreadsheet?

  6. Aaron Fulkerson Says:

    This extension can’t, but you can use other extensions to do this. Keep in mind, the acceptable data for Google Charts and Graphs is pretty limited. I’ll post more about this in a moment.

  7. Google Charts and Graphs Redux With a Mashup | MindTouch Blog Says:

    [...] an example mashup of Google Charts with some data store using DekiScript in Deki Wiki to compliment Corey’s previous blog post. We spoke about it for about 2 minutes this morning. A few minutes ago Steve showed me [...]

  8. Jon Says:

    My GUI for the charts API is at Google Charts. Thanks!

  9. Miguel Says:

    Impressive and useful.

    Pity that extension is not yet enabled on the Wik.is version :-) . Found out after a while trying to find what I was doing wrong.

    Looking forward to it.

    Best regards,

    Miguel

  10. Aaron Fulkerson Says:

    Miguel,

    Wik.is is running 1.8.2. This is 1.8.3. You can only check out this source code from SVN. Check out this post: http://www.mindtouch.com/blog/2007/12/12/google-charts-and-graphs-redux-with-a-mashup/

  11. Anton Shevchuk Says:

    My GUI: http://charts.hohli.com – Online Charts Builder based on this API

  12. Adam Says:

    Here’s our effort of a really loosely coupled Google API chart wrapper class for PHP:

    http://www.talkphp.com/script-giveaway/1704-googlecharts.html

  13. Leon Libberton Says:

    Sweet Post!