| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 5 |
<title>Flot Examples: Axes autoscaling options</title> |
| 6 |
<link href="../examples.css" rel="stylesheet" type="text/css"> |
| 7 |
<script language="javascript" type="text/javascript" src="../../source/jquery.js"></script> |
| 8 |
<script language="javascript" type="text/javascript" src="../../lib/jquery.mousewheel.js"></script> |
| 9 |
<script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script> |
| 10 |
<script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script> |
| 11 |
<script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script> |
| 12 |
<script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script> |
| 13 |
<script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script> |
| 14 |
<script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script> |
| 15 |
<script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script> |
| 16 |
<script type="text/javascript"> |
| 17 |
|
| 18 |
$(function() { |
| 19 |
var index = 0; |
| 20 |
function generate(start, end, fn) { |
| 21 |
var res = []; |
| 22 |
for (var i = 0; i <= 40; ++i) { |
| 23 |
var x = start + i / 40 * (end - start); |
| 24 |
res.push([x, fn(x)]); |
| 25 |
} |
| 26 |
return res; |
| 27 |
} |
| 28 |
|
| 29 |
var data = [ |
| 30 |
{ data: generate(index, 2, function (x) { return Math.cos(x);}), xaxis: 1, yaxis:1, lines: { show: true}} |
| 31 |
]; |
| 32 |
|
| 33 |
var plot = $.plot("#placeholder", data, { |
| 34 |
xaxes: [ |
| 35 |
{ position: 'bottom' } |
| 36 |
], |
| 37 |
yaxes: [ |
| 38 |
{ position: 'left', autoScale: 'none', min: -2.0, max: 2.0 } |
| 39 |
], |
| 40 |
zoom: { |
| 41 |
interactive: true |
| 42 |
}, |
| 43 |
pan: { |
| 44 |
interactive: true |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
function update () { |
| 49 |
index += 0.01; |
| 50 |
data = [ |
| 51 |
{ data: generate(index, index + 2, function (x) { return Math.cos(x);}), xaxis: 1, yaxis:1, lines: { show: true}} |
| 52 |
]; |
| 53 |
plot.setData(data); |
| 54 |
plot.setupGrid(true); |
| 55 |
plot.draw(); |
| 56 |
window.requestAnimationFrame(update); |
| 57 |
} |
| 58 |
|
| 59 |
window.requestAnimationFrame(update); |
| 60 |
|
| 61 |
$('#myForm input').on('change', function() { |
| 62 |
var val = $('input[name="myRadio"]:checked', '#myForm').val() |
| 63 |
var y = plot.getAxes().yaxis; |
| 64 |
y.options.min = -2.0; |
| 65 |
y.options.max = 2.0; |
| 66 |
y.options.autoScaleMargin = null; |
| 67 |
y.options.autoScale = "loose"; |
| 68 |
y.options.growOnly = false; |
| 69 |
|
| 70 |
switch (val) { |
| 71 |
case '1': |
| 72 |
y.options.autoScale = "none"; |
| 73 |
break; |
| 74 |
case '2': |
| 75 |
y.options.autoScaleMargin = 0.1; |
| 76 |
y.options.autoScale = "loose"; |
| 77 |
break; |
| 78 |
case '3': |
| 79 |
y.options.autoScale = "exact"; |
| 80 |
break; |
| 81 |
case '4': |
| 82 |
y.options.autoScaleMargin = 0.1; |
| 83 |
y.options.autoScale = "loose"; |
| 84 |
y.options.growOnly = true; |
| 85 |
break; |
| 86 |
case '5': |
| 87 |
y.options.autoScale = "exact"; |
| 88 |
y.options.growOnly = true; |
| 89 |
break; |
| 90 |
} |
| 91 |
}); |
| 92 |
}); |
| 93 |
|
| 94 |
</script> |
| 95 |
</head> |
| 96 |
<body> |
| 97 |
|
| 98 |
<div id="header"> |
| 99 |
<h2>Axes autoscaling options</h2> |
| 100 |
</div> |
| 101 |
|
| 102 |
<div id="content"> |
| 103 |
|
| 104 |
<div class="demo-container"> |
| 105 |
<div id="placeholder" class="demo-placeholder"></div> |
| 106 |
</div> |
| 107 |
<fieldset id="myForm"> |
| 108 |
<legend>Vertical axis autoscaling options</legend> |
| 109 |
<input type="radio" name="myRadio" value="1" checked="checked" /> None (min = -2.0, max = 2.0) <br /> |
| 110 |
<input type="radio" name="myRadio" value="2" /> fit loosely <br /> |
| 111 |
<input type="radio" name="myRadio" value="3" /> fit exactly <br /> |
| 112 |
<input type="radio" name="myRadio" value="4" /> grow loosely <br /> |
| 113 |
<input type="radio" name="myRadio" value="5" /> grow exactly <br /> |
| 114 |
</fieldset> |
| 115 |
</div> |
| 116 |
</body> |
| 117 |
</html> |