From FridaV
/* Any JavaScript here will be loaded for all users on every page load. */
plot_options = {
yaxis: { min: 0 },
xaxis: { },
points: { show: true },
lines: { show: true },
legend: { position: 'nw' },
};
var charts = {
chart: {},
init: function() {
$('table.flot').each(function(i) {
var my_id=$(this).attr('id');
var my_chart={cols:{}, ncols:[], series:{}};
charts.chart[my_id]=my_chart;
// get fields
$('tr:first th',this).each(function(j) {
var name=this.innerHTML;
my_chart.cols[name]=j;
my_chart.ncols.push(name);
this.onclick=function(e) { charts.toggle_series(my_id,name,e); }
}); // fields
// get rows
$('tr',this).each(function(j) {
if(j>=1) {
// var epoch=$('th.day',this).attr('epoch')*1000;
var epoch=1-j;
$('td',this).each(function(ii) { // columns
var a=my_chart.ncols[ii];
var v=this.innerHTML;
if((!v) || v=='None') v=0;
if(!my_chart.series[a]) my_chart.series[a]={ label: a , data: [] };
this.onclick=function(e) { charts.toggle_series(my_id,a,e); }
my_chart.series[a].data.unshift([epoch,parseFloat(v)]);
}); // columns
}
}); // rows
return;
}); // tables
}, // init()
toggle_series: function(id,name,e) {
var my_chart=charts.chart[id];
$('#'+id+' tr').each(function(i) {
if(i<1) {
$('th:eq('+my_chart.cols[name]+')',this).toggleClass('plot');
} else {
$('td:eq('+my_chart.cols[name]+')',this).toggleClass('plot');
}
});
charts.plot(id);
}, // toggle_series()
plot: function(id) {
if($('#'+id+'-flot-chart').length==0) {
// create plotarea
$('#'+id).before('<div class="flot-chart" id="'+id+'-flot-chart"/></div>');
}
var data=[];
$('#'+id+' tr:first th.plot').each(function(i) {
var name=this.innerHTML;
if(charts.chart[id].series[name]) {
data.push(charts.chart[id].series[name]);
}
});
if(data.length>0) {
$.plot($('#'+id+'-flot-chart'), data, plot_options);
$('#'+id+'-flot-chart').show(1);
} else {
$('#'+id+'-flot-chart').hide(1);
}
}
}
$(document).ready(charts.init);