wiki:TracYetAnotherChartMacro

Create bar/line/pie charts of query results

Notice: The plugin is at its very infancy (May 2018) so only a fraction of plotly's functionality is supported, parameter syntax may change a bit and error checking is very likely to be improveable.

Notice: Enabling this plugin completely breaks almost all security barriers as a result of full database access.

Description

This macro allows you to create a bar/line/pie chart of a SQL query output using the plotly.js JavaScript plotting engine in your Trac wiki pages and ticket pages. Plotly itself is MIT licensed.

The plugin egg contains plotly.js, ie there are no external web references.

A given wiki page can contain any number of plots.

Enter the following in your wiki page:

[[yachart(id=first; title=Action statuses; query=SELECT status, COUNT(status) FROM ticket WHERE type = 'Action' GROUP BY status)]]

This will result in something like this:

Bar chart example

Note the use of semicolon (;) as the delimiter character for the macro arguments. This is chosen to avoid ambiguity with commas which are common in SQL queries.

The query must return two columns. In line and bar charts, the first column will be used as x-axis data and the second column as y-axis data. In pie charts, the columns will be used as labels and values, respectively.

In the query, the macro will replace the string $USER with the id of the user logged in. This can be used to display "my tickets":

WikiProcessor syntax is supported which may make queries easier to read and write:

{{{#!yachart
   id=something;
   title=something else;
   query=SELECT status, COUNT(status) 
         FROM ticket 
         WHERE type = 'Action' 
         GROUP BY status;
}}}

Parameters

id            = dom-name     # The name of the HTML DOM carrying the chart. Mandatory. Must be unique for each macro call on a wiki page
title         = title-text   # The headline shown above the chart. Default: blank.
chart_type    = bar|line|pie # Optional; default: bar
query         = sql-query    # Mandatory
width         = pixel-width  # Optional; default: 600 
height        = pixel-height # Optional: default: 400
top_margin    = pixel-height # Optional; default: 50
bottom_margin = pixel-height # Optional; default: 30
left_margin   = pixel-height # Optional; default: 5
right_margin  = pixel-height # Optional; default: 5

The default margin sizes are a compromise that will fit many bar and pie charts, but expect to fiddle a bit with the margins if your query returns e.g. many long-named categories for a pie chart.

All defaults can be modified through the admin panel "yachart".

The background of this plugin is also discussed in trac-users:uNnJinrqW6Y.

Bugs/Feature Requests

Existing bugs and feature requests for TracYetAnotherChartMacro are here.

If you have any issues, create a new ticket.

defect

1 / 1

Download

Download the zipped source from here.

Source

You can check out TracYetAnotherChartMacro from here using Subversion, or browse the source with Trac.

Installation

General instructions on installing Trac plugins can be found on the TracPlugins page.

Recent Changes

17240 by rjollos on 2018-07-17 02:12:33
Add installation requirements

Fixes #13449.

17196 by thenor on 2018-06-06 19:34:02
fix incorrect read of utf-8 data and remove possible newlines in text data (makes plotly fail with a browser console message)
17183 by thenor on 2018-05-23 19:33:38
Add margin control, fix plot size control, add admin panel
(more)

Author/Contributors

Author: thenor
Maintainer: Theodor Norup
Contributors:

Last modified 8 months ago Last modified on Oct 8, 2018, 8:56:51 PM

Attachments (2)

Download all attachments as: .zip