1 |
/* from example at http://people.iola.dk/olau/flot/examples/turning-series.html */ |
2 |
|
3 |
// hard-code color indices to prevent them from shifting as |
4 |
// countries are turned on/off |
5 |
var i = 0; |
6 |
$.each(datasets, function(key, val) { |
7 |
val.color = i; |
8 |
++i; |
9 |
}); |
10 |
|
11 |
// insert checkboxes |
12 |
var choiceContainer = $("#choices"); |
13 |
$.each(datasets, function(key, val) { |
14 |
choiceContainer.append('<br/><input type="checkbox" name="' + key + |
15 |
'" checked="checked" >' + val.label + '</input>'); |
16 |
}); |
17 |
choiceContainer.find("input").click(plotAccordingToChoices); |
18 |
|
19 |
|
20 |
function plotAccordingToChoices() { |
21 |
var data = []; |
22 |
|
23 |
choiceContainer.find("input:checked").each(function () { |
24 |
var key = $(this).attr("name"); |
25 |
if (key && datasets[key]) |
26 |
data.push(datasets[key]); |
27 |
}); |
28 |
|
29 |
if (data.length > 0) |
30 |
$.plot($("#placeholder"), data, options); |
31 |
} |
32 |
|
33 |
plotAccordingToChoices(); |
34 |
|