-
Notifications
You must be signed in to change notification settings - Fork 0
g language_charts_api
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:
- http://rest.g-language.org/chart?chd=1,2,3,4%7c1,3,2,4%7c1,2,3,4%7c 2,1,4,3&chs=640x480&cht=lxy
- http://rest.g-language.org/chart?chd=0.0,0.1,0.5,1.0%7c0.0,0.5,1.0,1.5&chs=640x480&cht=bw&chco=white
- http://rest.g-language.org/chart?chd=0.3,0.3,1.1,0.1,0.2,0.1,0.1&chs=640x480&cht=v
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.
A chart can be made by accessing a URL created manually.
Here are some instructions for creating a chart:
- Select a chart type available, which can be seen from our Chart Gallery. The chart type is specified by the chd.
- Prepare your chart data for drawing your chart. The data is specified by thechd 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.
- 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.
- Pass additional parameters. The parameters available for each chart are listed in the parameter documentation page.
- 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.
-
Get your chart image, by accessing the URL with a GET request via web browser, or by embedding the image into HTML using
tags. If the URL is too long, send a POST request instead.
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 |
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
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)
The size of the output chart is specified by the "chs" parameter. Data is to be passed in the format of widthxheight. When the output file format specified is a PDF, pixels are converted to inches, assuming the usage of 72 dpi.
ex.
chs=640x480
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 |
JPEG | jpeg |
PostScript | postscript |
ex.
chfmt=png
The title of a chart is specified by the "chtt" parameter. This may be any string value.
ex.
chtt=Sample Chart
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
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
The line style of the charts are specified by the "chls" parameter. Below is 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
The line type of the charts are specified by the "chlt" parameter. Below is 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
The legend of the charts are specified by the "chdl" parameter. The values should be separated with "|" characters.
ex.
chdl=fizz|buzz
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
Here are some minimalistic chart examples.
http://rest.g-language.org/chart?cht=lc&chd=1,3,2,4&chs=320x240
http://rest.g-language.org/chart?cht=lxy&chd=1,2,3,4%7c1,3,2,4%7c1,2,3,4%7c2,1,4,3&chs=320x240
http://rest.g-language.org/chart?cht=p&chd=1,1,1,1,1&chs=320x240&chco=mat
http://rest.g-language.org/chart?cht=bw&chd=1,2,3,4&chs=320x240
http://rest.g-language.org/chart?cht=s&chd=1,2,3,4%7c1,3,2,4%7c1,2,3,4%7c2,1,4,3&chs=320x240
http://rest.g-language.org/chart?cht=b&chd=1,2,3,4&chs=320x240&chco=mat
http://rest.g-language.org/chart?cht=h&chd=rnorm(1000)&chs=320x240
http://rest.g-language.org/chart?cht=v&chd=0.3,0.3,1.1,0.1,0.2,0.1,0.1&chs=320x240
-
G-language Maps
- Institute for Advanced Biosciences
- E-Cell Simulation Environment
- E.coli multi-omics database
- Database of bacterial replication terminus
Kazuharu Arakawa, Ph.D.
G-language Project Leader Associate Professor
Institute for Advanced Biosciences Keio University
997-0017 Japan Tel/Fax: +81-235-29-0800 gaou@sfc.keio.ac.jp