/*
* Additional function for charts.html
* Written by ThemePixels
* http://themepixels.com/
*
* Built for Katniss Premium Admin Template
* http://themepixels.com/themes/demo/webpage/katniss
*/
jQuery(document).ready(function(){
/*****SIMPLE CHART*****/
var flash = [[0, 2], [1, 6], [2,3], [3, 8], [4, 5], [5, 13], [6, 8]];
var html5 = [[0, 5], [1, 4], [2,4], [3, 1], [4, 9], [5, 10], [6, 13]];
function showTooltip(x, y, contents) {
jQuery('
' + contents + '
').css( {
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5
}).appendTo("body").fadeIn(200);
}
var plot = jQuery.plot(jQuery("#chartplace"),
[ { data: flash, label: "Flash(x)", color: "#f9ac05"}, { data: html5, label: "HTML5(x)", color: "#72f905"} ], {
series: {
lines: { show: true, fill: true, fillColor: { colors: [ { opacity: 0.05 }, { opacity: 0.15 } ] } },
points: { show: true }
},
legend: { position: 'nw'},
grid: { hoverable: true, clickable: true, borderColor: '#ccc', borderWidth: 1, labelMargin: 10 },
yaxis: { min: 0, max: 15 }
});
var previousPoint = null;
jQuery("#chartplace").bind("plothover", function (event, pos, item) {
jQuery("#x").text(pos.x.toFixed(2));
jQuery("#y").text(pos.y.toFixed(2));
if(item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
jQuery("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY,
item.series.label + " of " + x + " = " + y);
}
} else {
jQuery("#tooltip").remove();
previousPoint = null;
}
});
jQuery("#chartplace").bind("plotclick", function (event, pos, item) {
if (item) {
jQuery("#clickdata").text("You clicked point " + item.dataIndex + " in " + item.series.label + ".");
plot.highlight(item.series, item.datapoint);
}
});
/*****BAR GRAPH*****/
var d2 = [];
for (var i = 0; i <= 10; i += 1)
d2.push([i, parseInt(Math.random() * 30)]);
var stack = 0, bars = true, lines = false, steps = false;
jQuery.plot(jQuery("#bargraph"), [ d2 ], {
series: {
stack: stack,
lines: { show: lines, fill: true, steps: steps },
bars: { show: bars, barWidth: 0.6 }
},
grid: { hoverable: true, clickable: true, borderColor: '#ccc', borderWidth: 1, labelMargin: 10 },
colors: ["#f93905"]
});
/**PIE CHART IN MAIN PAGE WHERE LABELS ARE INSIDE THE PIE CHART**/
var data = [];
var series = 5;
for( var i = 0; i 0)
data = data.slice(1);
// do a random walk
while (data.length < totalPoints) {
var prev = data.length > 0 ? data[data.length - 1] : 50;
var y = prev + Math.random() * 10 - 5;
if (y < 0)
y = 0;
if (y > 100)
y = 100;
data.push(y);
}
// zip the generated y values with the x values
var res = [];
for (var i = 0; i < data.length; ++i)
res.push([i, data[i]])
return res;
}
// setup control widget
var updateInterval = 1000;
jQuery("#updateInterval").val(updateInterval).change(function () {
var v = jQuery(this).val();
if (v && !isNaN(+v)) {
updateInterval = +v;
if (updateInterval < 1)
updateInterval = 1;
if (updateInterval > 2000)
updateInterval = 2000;
jQuery(this).val("" + updateInterval);
}
});
// setup plot
var options = {
colors: ["#05d4f9"],
series: { lines: { fill: true, fillColor: { colors: [ { opacity: 0.1 }, { opacity: 0.5 } ] } }, shadowSize: 0, }, // drawing is faster without shadows
yaxis: { min: 0, max: 100 },
grid: { borderColor: '#ccc', borderWidth: 1},
};
var plot = jQuery.plot(jQuery("#realtime"), [ getRandomData() ], options);
function update() {
plot.setData([ getRandomData() ]);
// since the axes don't change, we don't need to call plot.setupGrid()
plot.draw();
setTimeout(update, updateInterval);
}
update();
});