Clear prevCallbacks on detach()
[dygraphs.git] / tests / value-axis-formatters.html
... / ...
CommitLineData
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>valueFormatter and axisLabelFormatter</title>
5 <!--
6 For production (minified) code, use:
7 <script type="text/javascript" src="dygraph-combined.js"></script>
8 -->
9 <script type="text/javascript" src="../dygraph-dev.js"></script>
10
11 </head>
12 <body style="max-width: 800px;">
13 <h2>Multiple y-axes</h2>
14 <p>This demonstrates how the valueFormatter and axisLabelFormatter options work. The valueFormatter controls the display of the legend. The axisLabelFormatter controls the display of axis tick marks. These can be set on a per-axis basis.</p>
15 <div id="demodiv"></div>
16
17 <ul>
18 <li>xvf = x-axis valueFormatter
19 <li>yvf = y-axis valueFormatter
20 <li>y2vf = secondary y-axis valueFormatter
21 <li>xalf = x-axis axisLabelFormatter
22 <li>yalf = y-axis axisLabelFormatter
23 <li>y2alf = secondary y-axis axisLabelFormatter
24 </ul>
25
26 <script type="text/javascript">
27 var data = [];
28 for (var i = 1; i <= 100; i++) {
29 var m = "01", d = i;
30 if (d > 31) { m = "02"; d -= 31; }
31 if (m == "02" && d > 28) { m = "03"; d -= 28; }
32 if (m == "03" && d > 31) { m = "04"; d -= 31; }
33 if (d < 10) d = "0" + d;
34 // two series, one with range 1-100, one with range 1-2M
35 data.push([new Date("2010/" + m + "/" + d),
36 i,
37 100 - i,
38 1e6 * (1 + i * (100 - i) / (50 * 50)),
39 1e6 * (2 - i * (100 - i) / (50 * 50))]);
40 }
41
42 function formatDate(d) {
43 var yyyy = d.getFullYear(),
44 mm = d.getMonth() + 1,
45 dd = d.getDate();
46 return yyyy + '-' + (mm < 10 ? '0' : '') + mm + (dd < 10 ? '0' : '') + dd;
47 }
48
49 g = new Dygraph(
50 document.getElementById("demodiv"),
51 data,
52 {
53 labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
54 width: 640,
55 height: 350,
56 series: {
57 'Y3': { axis: 'y2' },
58 'Y4': { axis: 'y2' }
59 },
60 xAxisLabelWidth: 100,
61 yAxisLabelWidth: 100,
62 axes: {
63 x: {
64 valueFormatter: function(ms) {
65 return 'xvf(' + formatDate(new Date(ms)) + ')';
66 },
67 axisLabelFormatter: function(d) {
68 return 'xalf(' + formatDate(d) + ')';
69 },
70 pixelsPerLabel: 100,
71 },
72 y: {
73 valueFormatter: function(y) {
74 return 'yvf(' + y.toPrecision(2) + ')';
75 },
76 axisLabelFormatter: function(y) {
77 return 'yalf(' + y.toPrecision(2) + ')';
78 }
79 },
80 y2: {
81 valueFormatter: function(y2) {
82 return 'y2vf(' + y2.toPrecision(2) + ')';
83 },
84 axisLabelFormatter: function(y2) {
85 return 'y2alf(' + y2.toPrecision(2) + ')';
86 }
87 }
88 }
89 }
90 );
91 </script>
92</body>
93</html>