Template:Graph

From 2009.igem.org

(Difference between revisions)
(Both examples now work.)
m
Line 29: Line 29:
{{graph|Team:Groningen/Graphs/Test}}
{{graph|Team:Groningen/Graphs/Test}}
-
And this is not limited to line charts, as [{{fullurl:Team:Groningen/Graphs/TestPie}}?action=edit Team:Groningen/Graphs/TestPie] shows:
+
And this is not limited to line charts, as [{{fullurl:Team:Groningen/Graphs/TestPie}}?action=edit Team:Groningen/Graphs/TestPie] shows (note that it could have been made to look a little nicer by tweaking the plot options):
{{graph|Team:Groningen/Graphs/TestPie}}
{{graph|Team:Groningen/Graphs/TestPie}}

Revision as of 17:10, 24 June 2009

This template lets any user of the Wiki include a graph in a Wiki page much like he/she can include an image. The graph is defined using JSON that describes the graph directly using the properties supported by the charting library in the Dojo Toolkit. It also includes a datasource that should point to a (publicly accessible) Google Docs spreadsheet.

Steps to get a graph onto the Wiki:

  1. Go to Google Docs and create a spreadsheet, which you fill with data to put in the graph (the data series should be organized in columns).
  2. Publish the spreadsheet by clicking on Share in the top-right corner (while the spreadsheet is still open) and then "Publish as a webpage". In this dialog, make sure you check "Automatically republish when changes are made" if you want the graphs to always use the latest data and then click "Start publishing". Now copy the URL in the text box in the lower half of the screen (without the "&output=html" bit), this is the data source!
  3. Create a Wiki page with the following text (replacing all the bits between '/*' and '*/' with whatever is appropriate in your case:
    {
    datasource: '/*data source url*/',
    width: '/*width, including a unit, e.g. 8cm*/',
    height: '/*height, including a unit, e.g. 5cm*/',
    series: [
    /* comma-separated list of data series to display, e.g. for just one data series: */
    {x: /*x column*/, y: /*y column*/ }
    ],
    {{defaultAxes|xtitle=/*time (s)*/|ytitle=/*concentration (µM)*/}},
    {{defaultPlot}}
    }
  4. Use
    {{graph|/*Wiki graph page name*/}}
    to use the graph in any Wiki page (note that any Wiki page using a graph must also use
    {{GraphHeader}}
    once).

As an example Team:Groningen/Graphs/Test can be rendered using:

{{graph|Team:Groningen/Graphs/Test}}

Which looks like this:

Loading graph...

And this is not limited to line charts, as Team:Groningen/Graphs/TestPie shows (note that it could have been made to look a little nicer by tweaking the plot options):

Loading graph...

Please note that any page using this template should also include Template:GraphHeader (once), this need not be at the beginning of the document.