I dropped development of Plotr, so instead give my new graphing library Flotr a try.
Plotr Legend Example
Example page how to use the Plotr Legend.
This example throws an error when browsing with IE. I haven’t figured out what’s going wrong yet, but the example contained in the Plotr zip package works in IE.
Horizontal oriented BarChart
// Define a dataset.
var dataset = {
'myFirstDataset': [[0, 1], [1, 1], [2, 1.414], [3, 1.73]],
'mySecondDataset': [[0, 0.3], [1, 2.67], [2, 1.34], [3, 1.73]],
'myThirdDataset': [[0, 0.46], [1, 1.45], [2, 2.5], [3, 1.2]],
'myFourthDataset': [[0, 0.86], [1, 0.83], [2, 3], [3, 1.73]]
};
// Define options.
var options = {
// Define a padding for the canvas node
padding: {left: 30, right: 0, top: 10, bottom: 30},
// Background color to render.
backgroundColor: '#f2f2f2',
// Use the predefined blue colorscheme.
colorScheme: 'blue',
// Render a horizontal oriented barchart.
barOrientation: 'horizontal',
// Set the labels.
xTicks: [
{v:0, label:'day 1'},
{v:1, label:'day 2'},
{v:2, label:'day 3'},
{v:3, label:'day 4'}
]
};
// Instantiate a new BarCart.
var horizontal = new Plotr.BarChart('bars1',options);
// Add a dataset to it.
horizontal.addDataset(dataset);
// Render it.
horizontal.render();
// Add a legend.
horizontal.addLegend($('bar_legend'));
/*
HTML:
<fieldset id=\"bar_legend\">
<legend>Legend</legend>
</fieldset>
*/
Vertical oriented BarChart
// Define a new dataset.
dataset = {
'January': [[0, 3], [1, 2], [2, 1.414], [3, 2.3]],
'February': [[0, 1.4], [1, 2.67], [2, 1.34], [3, 1.2]],
'March': [[0, 0.46], [1, 1.45], [2, 1.0], [3, 1.6]],
'April': [[0, 0.3], [1, 0.83], [2, 0.7], [3, 0.2]]
};
// Define new options.
options = {
// Define a padding for the canvas node
padding: {left: 30, right: 0, top: 10, bottom: 30},
// Set a custom colorScheme
colorScheme: new Hash({
'January': '#1c4a7e',
'February': '#bb5b3d',
'March': '#3a8133',
'April': '#813379'
}),
// Background color to render.
backgroundColor: '#f2f2f2',
shouldFill: false,
// Set the labels.
xTicks: [
{v:0, label:'IE6'},
{v:1, label:'IE7'},
{v:2, label:'FF2'},
{v:3, label:'Opera 9'}
]
};
// Instantiate a new LineCart.
var line = new Plotr.LineChart('lines1',options);
// Add a dataset to it.
line.addDataset(dataset);
// Render it.
line.render();
// Add a legend.
line.addLegend($('lines_legend'));
[...] Legend example [...]