GChart Project Page › GChart: Encoding types and data

We use charts to clarify data, so it’s very important you know how to pass data to GChart. The Google Chart API accepts data in three encodings, which compress the data. GChart accepts data arrays, and convert those arrays into the encoding you choose. In this article I’ll show how to pass data to GChart, and I’ll show the differences between the three encodings.

Passing data to GChart

You can pass data to GChart in two ways. The first way is to set the data option to an already encoded String (don’t forget to set the right encoding option). The second way is to set data to an array containing the data. Here are some examples:

// Passing already encoded data:
...
data: 'F8Ke',		// => 5,60,10,30 encoded
encoding: 's',		// => Simple encoding
...
// Passing the same data but as an Array:
...
data: [5,60,10,30],	// => Single dataset to encode
encoding: ’s’,		// => Simple encoding
…
// Passing multiple datasets as a String or Array:
…
data: ‘F8Ke,yicP’,	// => 5,60,10,30 and 50,34,28,15 encoded (’,’ is the separator)
encoding: ’s’,		// => Simple encoding
…
data: [[5,60,10,30],[50,34,28,15]],	// => Multiple datasets to encoded
encoding: ’s’,		// => Simple encoding
…

Encoding types

There are three encoding types that are supported by the Google Chart API. The Google Chart API Project page tells us:

The following encoding formats are available:

  • Simple encoding has a resolution of 62 different values. Allowing five pixels per data point, this is sufficient for line and bar charts up to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size.
  • Text encoding has a resolution of 1,000 different values, using floating point numbers between 0.0 and 100.0. Allowing five pixels per data point, integers (1.0, 2.0, and so on) are sufficient for line and bar charts up to about 500 pixels. Include a single decimal place (35.7 for example) if you require higher resolution. Text encoding is suitable for all other types of chart regardless of size.
  • Extended encoding has a resolution of 4,096 different values and is best used for large charts where a large data range is required.

You can read more about it at the Google Chart API Project Page.