Plotr Project PageDocumentation › Plotr Datasets

Understanding datasets when using Plotr is very important. While it’s not hard to understand, you need to know a couple of things before you can work with them.

What’s a dataset?

A dataset is an Array of Arrays. Datasets are defined in objects, these objects are treated like hashes. Each dataset is represented with a different key, these keys need to be unique, but the value corresponding to the key doesn’t have to be unique. Such an object containing three datasets might look like this:

var data_obj = {
	'dataset1': [[0, 1], [1, 2.2], [2, 1.414], [3, 4], [4, 3.4]],
	‘another’: [[0, 0.7], [1, 2.67], [2, 1.34], [3, 3], [4, 3.2]],
	‘dataset3′: [[0, 0.46], [1, 1.45], [2, 2.5], [3, 1.2], [4, 2.4]]
};

The Array that represents the dataset is an array of (x, y) values.

Adding datasets to a chart

There are two ways to add datasets to a chart: using a data object or using a table. When you’ve already seen the Plotr Configurator I guess you know how to add a dataset by using a data object:

// Define data.
var data_obj = {
	'myFirstDataset': [[0, 1], [1, 2.2], [2, 1.414], [3, 4], [4, 3.4]],
	‘mySecondDataset’: [[0, 0.7], [1, 2.67], [2, 1.34], [3, 3], [4, 3.2]],
	‘myThirdDataset’: [[0, 0.46], [1, 1.45], [2, 2.5], [3, 1.2], [4, 2.4]],
	‘myFourthDataset’: [[0, 0.86], [1, 0.83], [2, 0.2], [3, 1.73], [4, 0.76]],
	‘myFifthDataset’: [[0, 0.45], [1, 0.2], [2, 0.5], [3, 0.8], [4, 0.1]]
};
…
var chart = new Plotr.BarChart(’plotr’, options);
// Add the datasets
chart.addDataset(data_obj);
…

When you have more than one Object with datasets, you can call addDataset() again. The passed object will be merged with the stored datasets.

// Define data.
var obj1 = {
	'd1': [[0, 1], [1, 1], [2, 1.414], [3, 1.73]],
	‘d2′: [[0, 0.3], [1, 2.67], [2, 1.34], [3, 1.73]],
	‘d3′: [[0, 0.46], [1, 1.45], [2, 2.5], [3, 1.2]]
};
var obj2 = {
	‘d0′: [[0, 0.3], [1, 2.67], [2, 1.34], [3, 1.73]],
	‘d3′: [[0, 0.46], [1, 1.45], [2, 2.5], [3, 1.2]]
};
…
var chart = new Plotr.BarChart(’plotr’, options);
// Chart has datasets ‘d1′, ‘d2′ and ‘d3′
chart.addDataset(obj1);
// Chart has datasets ‘d0′, ‘d1′, ‘d2′ and ‘d3′ (’d3′ from obj2)
chart.addDataset(obj2);
…

This stuff is pretty straightforward. Using data from tables is a little harder, but you should be able to format and parse your own tables after reading the next paragraph.

Adding table data to Plotr charts

A table needs to be coded in a way Plotr can parse it. When the table is correctly formatted, Plotr can read the datasets from it, and also read the labels. In order to add labels, a element must be present in the table. All data should be within the
element.