Chart API Available in Templates
The PocketQuery Javascript API offers a way to draw Google Charts. These work well in combination with the general PocketQuery JS API. If you want to see a walkthrough example of how to create a chart in PocketQuery, we recommend looking at this part of the Getting Started Guide.
A chart is created with the following method:
/**
* Draws a chart of the given type with the given options.
*/
PocketQuery.chart({String} type, {Object} options)
Inside a Template, the API can be called like this:
<script>
PocketQuery.chart("BarChart");
</script>
Type
The type is the chart name, i.e. the name of the respective package as defined by the Google Charts API in camel case. Among others the following chart types are available.
"BarChart" (version with material design: "Bar")
"LineChart" (version with material design: "Line")
"ScatterChart" (version with material design: "Scatter")
For a complete list, please refer to the Google Documentation and look up the package name of the chart type you want to draw.
Options
The options
object may contain the following:
All options that the Google Chart draw method expects: | A list of these options can typically be found at the bottom of the documentation of a specific chart type (example). |
All options that Google Chart format methods expect: | |
Deprecated, see How to Refactor dataTable to Converter | Array-of-arrays containing the dataset to be drawn. This overrides the data taken from the query results. Example: |
| CSS selector of the container (e.g. |
Deprecated, see How to Remove beforeDraw chart option | Callback function that is applied before the draw function of Google Chart is called. This function receives the prepared |
Example
<script>
PocketQuery.chart('BarChart', {
// Options of Google chart method
title: 'PocketQuery rocks!!!',
allowHtml: true,
showRowNumber: true,
height: 200,
width: 500,
// Google Chart formatting, see
// https://developers.google.com/chart/interactive/docs/reference#formatters
format: {
type: 'NumberFormat',
column: 1,
options: { // Options that the GC Formatting methods expect
prefix: '$',
negativeColor: 'red',
negativeParens: true
}
}
});
</script>