JavaScript
jQuery(document).ready(function(){
"use strict";
var newCust = [[0, 0], [1, 10], [2,5], [3, 12], [4, 5], [5, 8], [6, 0]];
var retCust = [[0, 0], [1, 8], [2,3], [3, 10], [4, 3], [5, 6], [6,0]];
var plot = jQuery.plot(jQuery("#basicflot"),
[{
data: newCust,
label: "Product 1",
color: "#007ACC"
},
{
data: retCust,
label: "Product 2",
color: "#58B55E"
}
],
{
series: {
lines: {
show: false
},
splines: {
show: true,
tension: 0.4,
lineWidth: 1,
fill: 0.4
},
shadowSize: 0
},
points: {
show: true,
},
legend: {
container: '#basicFlotLegend',
noColumns: 0
},
grid: {
hoverable: true,
clickable: true,
borderColor: '#ddd',
borderWidth: 0,
labelMargin: 5,
backgroundColor: '#fff'
},
yaxis: {
min: 0,
max: 15,
color: '#eee'
},
xaxis: {
color: '#eee'
}
});
var previousPoint = null;
jQuery("#basicflot").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("#basicflot").bind("plotclick", function (event, pos, item) {
if (item) {
plot.highlight(item.series, item.datapoint);
}
});
});