Source: Google Charts for REBOL

A URL generator to access the Google Charts API — works with View, Core and CGI.

Usage

This is a rudimentary wrapper for the Google Charts API.  It takes some of the work out of generating API arguments, though knowledge of the API is still recommended.

The ‘chart function returns a URL.  It’s easy enough to view any of these examples in REBOL:

view layout [image chart [...]]

Basic Line Chart

‘Line’ is the default Chart Type:

chart [data: [10 95 60 95 10]]

chart [data: [10 95 60 95 10]]

Basic Bar Chart

Types can be specified, either by the preset words (see script) or by the chart types set in the Google API:

chart [type: 'bar data: [10 95 60 95 10] bars: [55 8]]

chart [type: 'bar data: [10 95 60 95 10] bars: [55 8]]

Data Sets

Data can be supplied as a single or multiple sets:

data: [1 2 3 4]
data: [[1 2] [3 4] [5 6]]

Styles

Basic styles can be supplied:

color: red
area: [color solid 255.153.0]
area: [[color solid 255.140.204][chart solid 0.204.204]]
bars: [40 5 10] ; width space group-space

Examples

chart [
title: "Chart Example"
type: 'pie
size: 350x150
labels: ["Red" "Green" "Blue"]
data: [50 40 10]
colors: reduce [red green blue]
area: [color solid 244.244.240]
]

My Chart

Example in response to Generate a Google PIE Chart:

do http://www.ross-gill.com/r/google-charts.r

clipdata: {Adsense Revenue^-300
Sponsors^-500
Gifts^-50
Others^-58}

chart [
title: "Revenue"
size: 650x300
type: 'pie

; extract raw data
data: parse/all clipdata "^/^-"
labels: extract data 2
data: extract/index data 2 2

; format data and labels
sum: 0
forall data [sum: sum + data/1: to-integer data/1]
forall data [change data round 100 * data/1 / sum]
forall labels [
labels/1: rejoin [labels/1 " " data/(index? labels) "%"]
]
]

Posted by Chris-RG, 42 days ago