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