index.html (2933B)
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: Interacting with axes</title> 6 <link href="../examples.css" rel="stylesheet" type="text/css"> 7 <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../../excanvas.min.js"></script><![endif]--> 8 <script language="javascript" type="text/javascript" src="../../jquery.js"></script> 9 <script language="javascript" type="text/javascript" src="../../jquery.flot.js"></script> 10 <script type="text/javascript"> 11 12 $(function() { 13 14 function generate(start, end, fn) { 15 var res = []; 16 for (var i = 0; i <= 100; ++i) { 17 var x = start + i / 100 * (end - start); 18 res.push([x, fn(x)]); 19 } 20 return res; 21 } 22 23 var data = [ 24 { data: generate(0, 10, function (x) { return Math.sqrt(x);}), xaxis: 1, yaxis:1 }, 25 { data: generate(0, 10, function (x) { return Math.sin(x);}), xaxis: 1, yaxis:2 }, 26 { data: generate(0, 10, function (x) { return Math.cos(x);}), xaxis: 1, yaxis:3 }, 27 { data: generate(2, 10, function (x) { return Math.tan(x);}), xaxis: 2, yaxis: 4 } 28 ]; 29 30 var plot = $.plot("#placeholder", data, { 31 xaxes: [ 32 { position: 'bottom' }, 33 { position: 'top'} 34 ], 35 yaxes: [ 36 { position: 'left' }, 37 { position: 'left' }, 38 { position: 'right' }, 39 { position: 'left' } 40 ] 41 }); 42 43 // Create a div for each axis 44 45 $.each(plot.getAxes(), function (i, axis) { 46 if (!axis.show) 47 return; 48 49 var box = axis.box; 50 51 $("<div class='axisTarget' style='position:absolute; left:" + box.left + "px; top:" + box.top + "px; width:" + box.width + "px; height:" + box.height + "px'></div>") 52 .data("axis.direction", axis.direction) 53 .data("axis.n", axis.n) 54 .css({ backgroundColor: "#f00", opacity: 0, cursor: "pointer" }) 55 .appendTo(plot.getPlaceholder()) 56 .hover( 57 function () { $(this).css({ opacity: 0.10 }) }, 58 function () { $(this).css({ opacity: 0 }) } 59 ) 60 .click(function () { 61 $("#click").text("You clicked the " + axis.direction + axis.n + "axis!") 62 }); 63 }); 64 65 // Add the Flot version string to the footer 66 67 $("#footer").prepend("Flot " + $.plot.version + " – "); 68 }); 69 70 </script> 71 </head> 72 <body> 73 74 <div id="header"> 75 <h2>Interacting with axes</h2> 76 </div> 77 78 <div id="content"> 79 80 <div class="demo-container"> 81 <div id="placeholder" class="demo-placeholder"></div> 82 </div> 83 84 <p>With multiple axes, you sometimes need to interact with them. A simple way to do this is to draw the plot, deduce the axis placements and insert a couple of divs on top to catch events.</p> 85 86 <p>Try clicking an axis.</p> 87 88 <p id="click"></p> 89 90 </div> 91 92 <div id="footer"> 93 Copyright © 2007 - 2013 IOLA and Ole Laursen 94 </div> 95 96 </body> 97 </html>