1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples: Graph Legend</title>
<link href="../examples.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-mousewheel/jquery.mousewheel.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.canvaswrapper.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.colorhelpers.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.saturated.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.browser.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.drawSeries.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.uiConstants.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.symbol.js"></script>
<script language="javascript" type="text/javascript" src="/usr/share/javascript/jquery-flot/jquery.flot.legend.js"></script>
<script type="text/javascript">
$(function() {
var plot;
function drawArrow(ctx, x, y, radius){
ctx.beginPath();
ctx.moveTo(x + radius, y + radius);
ctx.lineTo(x, y);
ctx.lineTo(x - radius, y + radius);
ctx.stroke();
}
function drawSemiCircle(ctx, x, y, radius){
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI, false);
ctx.moveTo(x - radius, y);
ctx.lineTo(x + radius, y);
ctx.stroke();
}
var data1 = [];
for (var i = 0; i < 3; i += 0.005) {
data1.push([i, 1.2 + Math.sin(i*10)]);
}
var data2 = [
[0,0],
[1,1],
[2,2],
[3,3]
];
var data2_points = {
show: true,
radius: 5,
fillColor: "dodgerblue",
symbol: "diamond",
};
var data3 = [
[.7,3,.2,.4],
[1.5,2.2,.3,.4],
[2.3,1,.5,.2]
];
var data3_points = {
show: true,
radius: 5,
};
var data4 = [
[1,2],
[2,0.5],
[2.7,2]
];
var data4_points = {
//do not show points
show: false,
radius: 5,
fillColor: "white",
};
var data5 = [
[1.3, 1],
[1.75, 2.5],
[2.5, 0.5]
];
var data = [
// area
{color: "cyan", lines: {show: true, fill: true}, data: data1, label: "Area"},
// bars
{color: "orange", bars: {show: true, align: "center", barWidth: 0.25}, data: data5, label: "Bars"},
//lines
{color: "forestgreen", lines: {show: true, lineWidth: 4}, points: data4_points, data: data4, label: "Lines"},
// points
{color: "indigo", points: data2_points, data: data2, label: "Points"},
// lines + points
{color: "red", lines: {show: true, lineWidth:2}, points: data3_points, data: data3, label: "Lines & Points"},
];
var legendContainer = document.getElementById("legendContainer");
var legendSettings = {
position: "nw",
show: true,
noColumns: 2,
container: legendContainer
};
$('#myForm input').on('change', function() {
var val = $('input[name="myRadio"]:checked', '#myForm').val();
$(legendContainer).html('');
switch (val) {
case 'se':
legendSettings.position = "se"
legendSettings.container = null;
break;
case 'sw':
legendSettings.position = "sw"
legendSettings.container = null;
break;
case 'ne':
legendSettings.position = "ne"
legendSettings.container = null;
break;
case 'nw':
legendSettings.position = "nw"
legendSettings.container = null;
break;
case 'container':
legendSettings.container = legendContainer;
break;
}
setupGraph();
});
setupGraph();
drawGraph();
function setupGraph() {
plot = $.plot($("#placeholder"), data , {
legend: legendSettings,
series: {
lines: {
show: false
}
},
xaxis: {
autoScale: "none",
min: 0,
max: 3
},
yaxis: {
autoScale: "none",
min: 0,
max: 3.5
},
zoom: {
interactive: true
},
pan: {
interactive: true
}
});
}
function drawGraph() {
plot.setData(data);
plot.setupGrid();
plot.draw();
requestAnimationFrame(drawGraph);
}
// Add the Flot version string to the footer
$("#footer").prepend("Flot " + $.plot.version + " – ");
});
</script>
</head>
<body>
<div id="header">
<h2>Graph Legend</h2>
</div>
<div id="content">
<div class="demo-container">
<div id="placeholder" class="demo-placeholder"></div>
</div>
<p>Legend Container:</p>
<div id="legendContainer" class="legend" style="width:9em;height:8em;border-style:solid;border-color:threedface"></div>
<div>
<fieldset id="myForm">
<legend>Legend Position</legend>
<input type="radio" name="myRadio" value="se"> SE - Over Graph <br>
<input type="radio" name="myRadio" value="sw"> SW - Over Graph <br>
<input type="radio" name="myRadio" value="ne"> NE - Over Graph <br>
<input type="radio" name="myRadio" value="nw"> NW - Over Graph <br>
<input type="radio" name="myRadio" value="container" checked="checked"> Container <br>
</fieldset>
</div>
</div>
<div id="footer">
Copyright © 2007 - 2014 IOLA and Ole Laursen
</div>
</body>
</html>
|