Render a table content with Google barchart

This feature took me some time to figure out how to render the content of a normal table with the google chart mashup. Believe it or not it’s just one line of code and a trick when you have headers in the table.

The one line looks like the following:
{{google.piechart(400,200,xml.list(page.xml, “//tr/td[2]”),xml.list(page.xml, “//tr/td[1]”), _,true)}}

How it works:
Dekiscript is a powerful language to manipulate content inside and between wikipages. The google barchart expect to “list”, one with the labels and one with the values. The trick is to extract the table content with dekiscript by using xml.list and page.xml. with xml.list you perform the XPath-Query “//tr/td[2]” on the XML representation of a page (page.xml). When you call page.xml without any parameter the actual page is returned.

Hint 2: when you have a header line in your table you must manually change the tags of the first row to which means in HTML this is a header row. The google barchart will then exclude this row. Maybe someone has an idea to solve this more elegant.

Simple as possible. Great job of mindtouch.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s