User Tools

Site Tools


g-language_charts_api

This is an old revision of the document!


G-language Charts API

Overview

G-language Charts API is a RESTful web service for creating charts by accessing a simple URL. The charts are generated via R programming language through a CGI accessible with both GET and POST requests. Some examples are shown below:

The URL should be specified in the following format:

http://rest.g-language.org/chart?cht=<chart_type>&chd=<chart_data>
&chs=<chart_size>&…additional_parameters…

which is basically identical to the deprecated Google Charts API.

Making a Chart

A chart can be made by accessing a URL created manually.

Here are some instructions for creating a chart:

  1. Select a chart type available, which can be seen from our Chart Gallery. The chart type is specified by the cht parameter.
  2. Prepare your chart data for drawing your chart. The data is specified by the chd parameter. Separate each series of values with "|" characters and each value with "," characters. Be careful as URL length is limited when accessing with a GET request, and if more length is needed try with a POST request.
  3. Specify the chart size. The size is specified by the chs parameter, passed as number x number. For PDF, values are converted to inch assuming 72 dpi.
  4. Pass additional parameters. The parameters available for each chart are listed in the [parameter]() documentation page.
  5. Build you URL string, according to the format above. The base URL for the API is http://rest.g-language.org/chart, followed with the parameters of your choice. Be sure to sanitize all HTML metacharacters in the URL when embedding into an HTML file.
  6. Get your chart image, by accessing the URL with a GET request via web browser, or by embedding the image into HTML using <img> tags. If the URL is too long, send a POST request instead.

Parameters

Here is a list of parameters available for styling your chart. Mandatory parameters have a star (*) by the name. More detailed information are provided below.

Parameter Description Chart Types
cht* Chart Type All charts
chd* Chart Data All charts
chs* Chart Size All charts
chfmt Image Format All charts
chtt Chart Title All charts
chxt Axes Labels All charts with X and Y axes
chco Chart Colors All charts
chls Line Styles Line chart
chlt Line Types Line chart
chdl Chart Legend All charts
chdlp Legend Position All charts

cht*

The type of chart to draw is specified by the "cht" parameter. A table of chart types and an example for each chart are shown in the Chart Gallery below. A quick list is as follows.

Chart Type Value
Line Chart lc
Line Chart (With x values) lxy
Pie Chart p
Box and Whisker Plot Chart bw
Scatter Plot Chart s
Bar Chart b
Histogram Chart h
Venn Diagram Chart v
ex.
cht=lxy

chd*

The data used for creating a chart is specified by the "chd" paramter. Data is to be passed as series of values, where series are separated with "|" characters and values are separated with "," characters. R format is supported otherwise.

ex.
chd=1,2,3,4,5|1,5,2,4,3
chd=rnorm(50)

chs*

The size of the output chart is specified by the "chs" parameter. Data is to be passed in the format of *width*x*height*. When the output file format specified is a PDF, pixels are converted to inches, assuming the usage of 72 dpi.

ex.
chs=640x480

chfmt

The output image format of the chart is specified by the "chfmt" parameter. A list of available formats is as follows.

Default is png.

Format Value
PNG png
PDF pdf
JPEG jpeg
PostScript postscript
ex.
chfmt=png

chtt

The title of a chart is specified by the "chtt" parameter. This may be any string value.

ex.
chtt=Sample Chart

chxt

The labels of the axes are specified by the "chxt" parameter. This may be any string value separated with a "," character. The option is valid for charts with x and y axes.

ex.
chxt=foo,bar

chco

The colors of the charts are specified by the "chco" parameter. There are two ways of passing values, which are either by using 6 digit hexadecimal values split by "," characters for each series, or the R way. The R native and RColorBrewer color libraries are available for use, and can be specified in the query. An easy way of using nice mat colors for the charts is by using the keyword "mat".

ex.
chco=ff0000,0000ff
chco=mat
chco=1,4

chls

The line style of the charts are specified by the "chls" parameter. Below are a list of types available.

Style Value
Points p
Lines l
Points and Lines b
"b" without Points c
Overlapping Points and Lines o
Vertical plots from x axis h
Step from the left value s
Step from the right value S
Plot the axes only n
ex.
chls=b

chlt

The line type of the charts are specified by the "chlt" parameter. Below are a list of lines available.

Type Value
Blank 0 or "blank"
Solid 1 or "solid"
Dashed 2 or "dashed"
Dotted 3 or "dotted"
Dot and Dash 4 or "dotdash"
Long Dash 5 or "longdash"
Two Dash 6 or "twodash"
ex.
chlt=1
chlt=solid

chdl

The legend of the charts are specified by the "chdl" parameter. The values should be separated with "|" characters.

ex.
chdl=fizz|buzz

chdlp

The legend positioning of the charts are specified by the "chdlp" parameter. The values can be set using keywords such as 'topleft' and 'bottom'.

ex.
chdlp=topleft

Chart Gallery

Here are some minimalistic chart examples.

Line chart

Line chart (with x and y values)

Pie chart

Box and whisker chart

Scatter plot chart

Bar chart

Histogram chart

Venn diagram

g-language_charts_api.1377758628.txt.gz · Last modified: 2014/01/18 07:44 (external edit)