User Tools

Site Tools


g-language_charts_api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
g-language_charts_api [2013/08/21 07:37]
celery removed
g-language_charts_api [2014/01/18 07:44] (current)
Line 2: Line 2:
  
 ===== Overview ===== ===== Overview =====
-The 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 methods. Some examples are shown below:+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=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.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]]   * [[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: The URL should be specified in the following format:
  
-  http://​rest.g-language.org/​chart?​cht=<​*chart type*>&​chd=<​*chart data*+  http://​rest.g-language.org/​chart?​cht=<​chart_type>&​chd=<​chart_data
-  &​chs=<​*chart size*>&​…*additional parameters*+  &​chs=<​chart_size>&​…additional_parameters
  
 which is basically identical to the deprecated Google Charts API. which is basically identical to the deprecated Google Charts API.
Line 20: Line 21:
 Here are some instructions for creating a chart: 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 [cht]() parameter.  +  - **Select a chart type** available, which can be seen from our [[#​chart_gallery|Chart Gallery]]. The chart type is specified by the [[#cht|cht]] parameter.  
-  - **Prepare your chart data** for drawing your chart. The data is specified by the [chd]() parameter. Separate each group 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 ​pass a POST request. +  - **Prepare your chart data** for drawing your chart. The data is specified by the [[#chd|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. 
-  - **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.+  - **Specify the chart size**. The size is specified by the [[#chs|chs]parameter, passed as //number// //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.   - **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.   - **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.
Line 28: Line 29:
  
 ====== Parameters ====== ====== 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|cht*]] ​   | Chart Type      | All charts ​ |
 +| [[#​chd|chd*]] ​   | Chart Data      | All charts ​ |
 +| [[#​chs|chs*]] ​   | Chart Size      | All charts ​ |
 +| [[#​chfmt|chfmt]] | Image Format ​   | All charts ​ |
 +| [[#​chtt|chtt]] ​  | Chart Title     | All charts ​ |
 +| [[#​chxt|chxt]] ​  | Axes Labels ​    | All charts with X and Y axes |
 +| [[#​chco|chco]] ​  | Chart Colors ​   | All charts ​ |
 +| [[#​chls|chls]] ​  | Line Styles ​    | Line chart  |
 +| [[#​chlt|chlt]] ​  | Line Types      | Line chart  |
 +| [[#​chdl|chdl]] ​  | Chart Legend ​   | All charts ​ |
 +| [[#​chdl|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 [[g-language_charts_api#​chart_gallery|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 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
 +
 +===== chlt =====
 +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
 +
 +===== 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 ====== ====== Chart Gallery ======
 +Here are some minimalistic chart examples.
 +
 +===== Line chart =====
 +
 +[[http://​rest.g-language.org/​chart?​cht=lc&​chd=1,​3,​2,​4&​chs=320x240]]
 +
 +<​html>​
 +<img src="​http://​rest.g-language.org/​chart?​cht=lc&​chd=1,​3,​2,​4&​chs=320x240"​ alt="​line"></​img>​
 +</​html>​
 +
 +===== Line chart (with x and y values) =====
 +
 +[[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]]
 +
 +<​html>​
 +<img src="​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"​ alt="​linexy"></​img>​
 +</​html>​
 +
 +===== Pie chart =====
 +
 +[[http://​rest.g-language.org/​chart?​cht=p&​chd=1,​1,​1,​1,​1&​chs=320x240&​chco=mat]]
 +
 +<​html>​
 +<img src="​http://​rest.g-language.org/​chart?​cht=p&​chd=1,​1,​1,​1,​1&​chs=320x240&​chco=mat"​ alt="​pie"></​img>​
 +</​html>​
 +
 +===== Box and whisker chart =====
 +
 +[[http://​rest.g-language.org/​chart?​cht=bw&​chd=1,​2,​3,​4&​chs=320x240]]
 +
 +<​html>​
 +<img src="​http://​rest.g-language.org/​chart?​cht=bw&​chd=1,​2,​3,​4&​chs=320x240"​ alt="​box&​whisker"></​img>​
 +</​html>​
 +
 +===== Scatter plot chart =====
 +
 +[[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]]
 +
 +<​html>​
 +<img src="​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"​ alt="​scatter"></​img>​
 +</​html>​
 +
 +===== Bar chart =====
 +
 +[[http://​rest.g-language.org/​chart?​cht=b&​chd=1,​2,​3,​4&​chs=320x240&​chco=mat]]
 +
 +<​html>​
 +<img src="​http://​rest.g-language.org/​chart?​cht=b&​chd=1,​2,​3,​4&​chs=320x240&​chco=mat"​ alt="​bar"></​img>​
 +</​html>​
 +
 +===== Histogram chart =====
 +
 +[[http://​rest.g-language.org/​chart?​cht=h&​chd=rnorm(1000)&​chs=320x240]]
 +
 +<​html>​
 +<img src="​http://​rest.g-language.org/​chart?​cht=h&​chd=rnorm(1000)&​chs=320x240"​ alt="​histogram"></​img>​
 +</​html>​
 +
 +===== Venn diagram =====
 +
 +[[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]]
 +
 +<​html>​
 +<img src="​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"​ alt="​venn"></​img>​
 +</​html>​
g-language_charts_api.1377070650.txt.gz · Last modified: 2014/01/18 07:44 (external edit)