Chart definition JSON
The Chart content element is configured entirely from a single JSON string. That string is accepted by:
AddChart(width, height, definition): Creates a chart from a definition.SetDefinition(definition): Replaces the definition of an existing chart.
See Charts for the API that hosts these definitions.
Chart definition JSON example
{
"chartType": "bar",
"title": "Revenue by region (thousands CAD)",
"theme": "nature",
"data": {
"categories": { "data": ["Q1", "Q2", "Q3", "Q4"] },
"series": [
{ "name": { "data": ["North America"] }, "data": { "data": [1250, 1410, 1580, 1720] } },
{ "name": { "data": ["Europe"] }, "data": { "data": [910, 980, 1120, 1180] } },
{ "name": { "data": ["Asia Pacific"] }, "data": { "data": [640, 720, 905, 1010] } }
]
}
}
Definition structure
The definition is a JSON object. All members are optional; anything omitted keeps its default.
Value ranges
Most leaf values in a chart definition are not plain arrays, but range objects. A range object carries the literal values and, optionally, a spreadsheet-style reference.
data
array
The literal values.
ref
string
Optional source range reference, retained as metadata so the chart can be re-linked to a spreadsheet. Ignored when rendering.
This wrapper is used for categories, series name, data, dataDomain, markerSize, and labels.
Data
The data object holds the category axis values and the list of series.
categories
range of strings
Labels for the category axis, shared by all series.
Series
Each element of series is an object.
name
range of strings
The series name, taken from the first array element. Used in the legend.
data
range of numbers
The series values, one per category.
dataDomain
range of numbers
Explicit X values, for scatter-style data where categories are not evenly spaced.
markerSize
range of numbers
Per-point marker sizes, producing a bubble-style rendering.
labels
range of strings
Explicit per-point data labels, overriding the formatted values.
showLabels
bool
Show data labels for every point of the series.
line
bool
Render the series as a line instead of columns. Radar series are always lines.
showTrendlineEq
bool
Display the fitted equation next to the trendline.
Series are matched to the existing chart series by their index in the array, which makes it possible to update only the data of an already configured chart.
Chart types
Chart types include:
Bar
Pie
Radar
Bar
The default family: a clustered column chart with a category axis and a value axis, gridlines, and a legend at the bottom. Individual series can be switched to lines with "line": true, which lets you mix columns and lines in one chart.
Pie
A single-series proportional chart. When the definition creates more than one series, a doughnut hole is applied automatically.

Radar
A polar chart where every category is an axis radiating from the center. Radar series are always rendered as lines, which makes this type well suited to scorecards and comparisons across several dimensions.

Themes
theme selects a palette that is applied to the series in order, cycling through eight colors. Values are case insensitive.
pastel
Soft pinks, peaches, mints and lavenders.
grayscale
Neutral grays, from near-black to near-white.
vivid
Saturated spectrum colors.
nature
Greens, olives and khakis.
sunset
Corals, ambers and deep purples.
If theme is omitted, the default series palette is used. Fill colors of column and pie series are applied with slight transparency, while line series use the palette color at full opacity.

Trendlines
Setting trendlineType on a bar/column series fits a curve through the data and draws it as a dashed line in a translucent variant of the series color. The trendline is named "<series name> (Trend)" in the legend.
Exp
Exponential
Linear
Least-squares straight line
Log
Logarithmic
MovingAvg
Moving average
Poly
Polynomial
Power
Power law
Values are matched case insensitively. Set "showTrendlineEq": true to print the fitted equation on the chart.

Using a definition from code
A complete definition is just a JSON object, so build it with your JSON library of choice and pass the serialized result to the chart API.
See Charts for the code that adds a chart in each supported language, along with sizing and replacement semantics.
Notes and troubleshooting
The definition must be a JSON object. A definition that is not a JSON object, or that is malformed, raises an exception.
Unknown members are ignored, so definitions can carry extra metadata safely.
Series values should align with categories. A series with fewer values than categories simply leaves the remaining categories empty.
Chart size lives in the API, not the JSON. Use
AddChart(width, height, ...)orSetWidthandSetHeight.Sizes are in points (1/72 inch), consistent with the rest of the document creation API.
Further Reading
Charts for the Chart API that hosts these definitions.
Last updated
Was this helpful?