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