WiseMeteringWiseMeteringchart-generator

WiseMetering · Reference

Chart generator

An HTTP service that turns Google Charts ChartWrapper JSON into PNG or SVG images. It renders ColumnChart, BarChart, PieChart and BubbleChart the way Google Charts does, without a browser and without network access.

Questions, API keys or problems with a chart: charts@wisemetering.com.

Request

POST / with Content-Type: application/json:

json
{
  "args": {
    "chartType": "ColumnChart",
    "dataTable": [["Month", "kWh"], ["Jan", 1250], ["Feb", 1130]],
    "options": {"width": 800, "height": 350, "colors": ["#688715"]}
  },
  "format": "png",
  "forceUncutLine": false
}
FieldDescription
args.chartTypeColumnChart, BarChart, PieChart or BubbleChart.
args.dataTableRows of data; the first row is the header. See each chart.
args.optionsGoogle Charts options; the supported ones are listed in Options for every chart and in each chart's section. Others are ignored.
formatpng (a data:image/png;base64,… string) or svg (markup). Default svg.
forceUncutLinetrue keeps the names of a pie's labeled legend on one line; otherwise long names wrap.

When API keys are required, send one as Authorization: Bearer <key>. GET /up and GET /health answer {"status":"ok"} (and GET /ping, ping, as the Node service did).

Responses

StatusWhenBody
200The chart was renderedThe PNG data URI or the SVG
400The chart couldn't be rendered{"error": "<message>"}, see Errors
401API keys are required (AUTH=required) and the request has no valid Authorization: Bearer <key>{"error": "unauthorized", "message": "missing or invalid API key", "hint": "…"}, with WWW-Authenticate: Bearer
404Unknown path{"error": "not_found", "message": "no such endpoint", "hint": "…"} (a page for browsers)
405Known path, wrong method{"error": "method_not_allowed", "message": "…"}

Errors

Messages of 400 responses:

MessageCause
request body too largeThe body is over 10 MB.
invalid JSON body: <details>The body isn't valid JSON.
[InputError] unsupported formatformat is neither png nor svg.
[InputError] chartOptions should be an object containing Google ChartWrapper optionsargs is missing or isn't an object.
[RenderingError] The chart type is not defined.args.chartType is missing.
[RenderingError] unsupported chartType <type>The chart type isn't one of ColumnChart, BarChart, PieChart, BubbleChart.
[RenderingError] The data table is not defined.args.dataTable is missing or isn't an array.
[RenderingError] Table has no columns.The header row is missing or isn't an array.
[RenderingError] Data column(s) for axis #0 cannot be of type stringThe header has only the label column, no series.
[RenderingError] Every row given must be either null or an array.A data row isn't an array.
[RenderingError] Data table has no rows with numeric x and yBubbleChart without any row with numeric x and y.
[RenderingError] internal error while rendering the chartA bug in the renderer. It is logged as ERROR with the request; the service keeps running.

Options for every chart

Options may be null; numbers may be strings ("50") and sizes percentages ("80%"). Colors are #rrggbb, #rgb, transparent or basic names.

OptionTypeDefaultDescription
widthnumber600Image width in px, capped at 4096.
heightnumber400Image height in px, capped at 4096.
backgroundColorcolor or {fill}#ffffffBackground; "transparent" keeps the PNG transparent.
backgroundColor.fillcolorSame as a color given directly.
colorsarray of colorsGoogle's paletteColors of the series (pie: slices; bubble: groups), cycled when there are more series than colors.
fontSizenumberderived from the sizeBase font size. By default 12 + (width + height − 790) / 315, rounded up from .6, as Google does.
chartArea.leftpx or %centeredLeft edge of the plot area.
chartArea.toppx or %centeredTop edge of the plot area.
chartArea.widthpx or %61.8% (wider on wide charts)Plot area width.
chartArea.heightpx or %61.8%Plot area height.
titlestringChart title, bold, above the plot area.
titleTextStyletext stylebold, blackStyle of the title.
legendstring or object{position: "right"}A position string, or an object with position and textStyle.
legend.positionstringrightbottom, top, right or none (pie charts also labeled).
legend.textStyletext style#222222Style of the legend entries.

Text styles

Every textStyle and titleTextStyle accepts:

OptionTypeDefaultDescription
fontSizenumberchart font sizeFont size in px (at most 200).
colorcolordepends on the textText color.
boldbooleanfalse (titles: true)Bold text. "true"/"false" strings are accepted.
italicbooleanfalseItalic text.

Text is always drawn in DejaVu Sans.

Chart

ColumnChart

Vertical bars and lines, on one or two value axes, optionally stacked.

Data

  • First row: header. First column: category labels (strings); each following column is a series.
  • A {"role": "style"} header after a series colors each bar: "#hex" or "color: #hex" (empty = series color).
  • A {"role": "annotation"} header after a series adds text above each bar.
  • null leaves a gap: no bar, or a break in a line. Numbers may be strings.

Options

Besides the options for every chart:

OptionTypeDefaultDescription
vAxis.minValuenumberExtends the axis to include this value.
vAxis.maxValuenumberExtends the axis to include this value ("automatic" is ignored).
vAxis.baselinenumberValue that must be on the axis; 0 makes bars start at zero.
vAxis.viewWindow.minnumberFixed axis start (with viewWindow.max).
vAxis.viewWindow.maxnumberFixed axis end (with viewWindow.min).
vAxis.formatstring#,##0 (en)Number format of the tick labels, e.g. #,##0.##.
vAxis.gridlines.colorcolor#ccccccMajor gridlines; transparent hides them.
vAxis.minorGridlines.colorcolor60% towards the backgroundMinor gridlines, one between majors.
vAxis.textStyletext style#444444Style of the tick labels.
vAxis.titlestringTitle of the left axis, rotated.
vAxis.titleTextStyletext style#222222Style of the axis titles.
vAxis.textPositionstringoutnone hides the tick labels.
vAxis.baselineColorcolor#333333Line at zero; transparent hides it.
vAxes.NobjectOverrides vAxis for axis N (0 = left, 1 = right): any of the vAxis keys above.
vAxes.N.titlestringTitle of axis N.
hAxis.textStyletext style#222222Style of the category labels.
hAxis.textColorcolorColor of the category labels (overrides textStyle.color).
hAxis.textPositionstringoutnone hides the category labels.
hAxis.slantedTextbooleanfalseRotates the category labels; crowded ones are thinned out.
hAxis.slantedTextAnglenumber30Rotation in degrees (up to 90).
series.N.typestringbarsbars or line (area and steppedArea are drawn as lines).
series.N.targetAxisIndexnumber00 = left axis, 1 = right axis.
series.N.colorcolorcolors[N]Color of series N.
series.N.lineWidthnumber2Line width in px; 0 hides the line.
series.N.lineDashStylearray of numbersDash pattern, e.g. [6, 4].
series.N.visibleInLegendbooleantrueLists the series in the legend.
lineWidthnumber2Line width of every line series.
isStackedbooleanfalseStacks the bars of each axis; lines are not stacked.
bar.groupWidthpx or %61.8%Width of a category's bars.
annotations.textStyletext stylebar color, darkenedStyle of annotation texts.
annotations.stem.lengthnumber12Length of the line between a bar and its annotation.

Examples

Simple
Simple

Title, axis title, zero baseline.

Grouped
Grouped

Several series side by side, legend at the bottom, vAxis.format.

Stacked
Stacked

isStacked, legend on top.

Bars and lines on two axes
Bars and lines on two axes

series.N.type, targetAxisIndex, lineDashStyle, labels at 90°.

Colors per bar and annotations
Colors per bar and annotations

style and annotation roles, hidden value axis.

Chart

BarChart

Horizontal bars: categories top to bottom, values along the bottom.

Data

  • Same as ColumnChart: labels, then series, with optional style and annotation role columns.
  • Negative values extend left of the baseline.

Options

Besides the options for every chart:

OptionTypeDefaultDescription
hAxis.minValuenumberExtends the axis to include this value.
hAxis.maxValuenumberExtends the axis to include this value ("automatic" is ignored).
hAxis.baselinenumberValue that must be on the axis; 0 makes bars start at zero.
hAxis.viewWindow.minnumberFixed axis start (with viewWindow.max).
hAxis.viewWindow.maxnumberFixed axis end (with viewWindow.min).
hAxis.formatstring#,##0 (en)Number format of the tick labels, e.g. #,##0.##.
hAxis.gridlines.colorcolor#ccccccMajor gridlines; transparent hides them.
hAxis.minorGridlines.colorcolor60% towards the backgroundMinor gridlines, one between majors.
hAxis.textStyletext style#444444Style of the tick labels.
hAxis.textColorcolorColor of the value labels; transparent hides them.
hAxis.textPositionstringoutnone hides the value labels.
hAxis.baselineColorcolor#333333Line at zero.
vAxis.textPositionstringoutCategory labels: out (left of the bars), in (inside the plot area) or none.
vAxis.textStyletext style#222222Style of the category labels.
vAxis.textColorcolorColor of the category labels.
bar.groupWidthpx or %61.8%Height of a category's bars.
annotations.textStyletext stylebar color, darkenedStyle of annotation texts, drawn after the bar (or the baseline, for negative values) with a 12px stem.

Examples

Simple
Simple

Labels left of the bars, value axis at the bottom.

Deviation
Deviation

Negative values, viewWindow, labels inside, colors per bar, annotations.

Chart

PieChart

Pie or donut, with percentages in the slices and a legend beside, below or around it.

Data

  • Rows of [label, value]. Negative values count as zero.
  • With legend labeled, names that don't fit beside the pie wrap onto several lines unless the request has "forceUncutLine": true.

Options

Besides the options for every chart:

OptionTypeDefaultDescription
pieHolenumber0Hole size from 0 (pie) to 0.95 (thin donut).
pieSliceTextstringpercentagepercentage or none. Percentages that don't fit in their slice are left out.
pieSliceTextStyletext style#ffffffStyle of the percentages.
sliceVisibilityThresholdnumber1/720Slices below this fraction of the total merge into one slice; 0 keeps all.
pieResidueSliceLabelstringOtherLabel of the merged slice.
pieResidueSliceColorcolor#ccccccColor of the merged slice.
legend.positionstringrightright, labeled (name and percentage beside each slice, with a leader line), bottom, top or none.

Examples

Pie
Pie

Percentages inside, legend on the right, title.

Donut, labeled
Donut, labeled

pieHole, legend labeled, small slices merged.

Donut, legend at the bottom
Donut, legend at the bottom

pieHole 0.5, legend bottom.

Chart

BubbleChart

Bubbles placed by x and y, colored by group and sized by a value.

Data

  • Rows of [id, x, y, group, size]; group and size are optional.
  • id is drawn on the bubble. Rows without numeric x and y are skipped.
  • Each distinct group gets the next color and a legend entry.
  • The radius goes from 5 to 30 px, with the bubble area linear in size.

Options

Besides the options for every chart:

OptionTypeDefaultDescription
hAxis.minValuenumberExtends the axis to include this value.
hAxis.maxValuenumberExtends the axis to include this value ("automatic" is ignored).
hAxis.baselinenumberValue that must be on the axis; 0 makes bars start at zero.
hAxis.viewWindow.minnumberFixed axis start (with viewWindow.max).
hAxis.viewWindow.maxnumberFixed axis end (with viewWindow.min).
hAxis.formatstring#,##0 (en)Number format of the tick labels, e.g. #,##0.##.
hAxis.gridlines.colorcolor#ccccccMajor gridlines; transparent hides them.
hAxis.minorGridlines.colorcolor60% towards the backgroundMinor gridlines, one between majors.
hAxis.textStyletext style#444444Style of the tick labels.
hAxis.titlestringTitle below the horizontal axis.
hAxis.titleTextStyletext style#222222Style of the horizontal axis title.
vAxis.minValuenumberExtends the axis to include this value.
vAxis.maxValuenumberExtends the axis to include this value ("automatic" is ignored).
vAxis.baselinenumberValue that must be on the axis; 0 makes bars start at zero.
vAxis.viewWindow.minnumberFixed axis start (with viewWindow.max).
vAxis.viewWindow.maxnumberFixed axis end (with viewWindow.min).
vAxis.formatstring#,##0 (en)Number format of the tick labels, e.g. #,##0.##.
vAxis.gridlines.colorcolor#ccccccMajor gridlines; transparent hides them.
vAxis.minorGridlines.colorcolor60% towards the backgroundMinor gridlines, one between majors.
vAxis.textStyletext style#444444Style of the tick labels.
vAxis.titlestringTitle of the vertical axis, rotated.
vAxis.titleTextStyletext style#222222Style of the vertical axis title.
bubble.textStyletext styleblack, chart font sizeStyle of the bubble labels.

Examples

Bubbles by group and size
Bubbles by group and size

Groups, sizes, axis titles, legend at the bottom.

Try it

Playground

Edit a request and render it with this service. It is sent to POST / as is.

Press Render (or Ctrl/⌘ + Enter)