Skip to content
xuexue edited this page Jul 31, 2012 · 8 revisions

All data objects used by Polychart are internally represented by a gg.data object. This object can be initiated data in JSON, arrays, CSV, or from an asynchronous source.

Calling gg.data() creates a new gg.data object. The constructor takes up to two parameters:

  • data -- the data object (in JSON, array, CSV), or a URL that returns a data object in an acceptable format
  • meta (optional) -- metadata consisting of headers/keys, the data type, and other information for each key.

Examples of accepted data formats are:

  • associate array of arrays: { x : [...], y : [...], z : [...], ... }
  • array of JSON objects: [ {x : ..., y : ..., }, {x : ..., y : ..., }, ... ]
  • array of arrays: [ [x1,y1,z1,...], [x2, y2, z2], ...]
  • string in CSV, with headers: "x,y,z\n 1,1,1\n 1,1,1\n ..."
  • a URL that returns a data object d. In this case d can be in one of the above formats, or d be an object with d.data being in one of the above formats and d.keys representing the keys.

Internally, the data is converted in to the second format (array of JSON objects).

The meta data can be one of the following:

  • an array indicating the headers/keys of the data set: ['x', 'y', 'z', ...]
  • an associate array mapping headers/keys to data type: {'x':'time', 'y':'numeric', 'z':'category'}
  • an associate array of objects, where each object can contain the type and format of the data.

Possible types of data are time, numeric and category. For time data, the format parameter describes the datetime format that the data is in. For more on time formatting, see https://github.com/mbostock/d3/wiki/Time-Formatting.

Derive a new column based on existing columns called newvarname. The parameter fnString is a string consisting of a JavaScript expression used to derive the new column based on an existing column. For example, if the existing dataset has columns x and y, the call derive('x+y', 'z') will create a new column z that is the sum of x and y.

Filters the datain the current data object, then constructs and returns a new gg.data object with just the filtered functions. The parameter filterfunc is a function that takes a data point and returns whether or not the data point should be kept. For example:

gg.data({x:[1,2,3,4,5,6]}).filter(function(d){ return d.x % 2 == 0 });

returns a gg.data object with just the even numbers.

Clone this wiki locally