Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
94 lines (89 sloc) 3.09 KB
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
<title>valueFormatter and axisLabelFormatter</title>
<!--[if IE]>
<script type="text/javascript" src="../excanvas.js"></script>
<![endif]-->
<!--
For production (minified) code, use:
<script type="text/javascript" src="dygraph-combined.js"></script>
-->
<script type="text/javascript" src="../dygraph-dev.js"></script>
</head>
<body style="max-width: 800px;">
<h2>Multiple y-axes</h2>
<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>
<div id="demodiv"></div>
<ul>
<li>xvf = x-axis valueFormatter
<li>yvf = y-axis valueFormatter
<li>y2vf = secondary y-axis valueFormatter
<li>xalf = x-axis axisLabelFormatter
<li>yalf = y-axis axisLabelFormatter
<li>y2alf = secondary y-axis axisLabelFormatter
</ul>
<script type="text/javascript">
var data = [];
for (var i = 1; i <= 100; i++) {
var m = "01", d = i;
if (d > 31) { m = "02"; d -= 31; }
if (m == "02" && d > 28) { m = "03"; d -= 28; }
if (m == "03" && d > 31) { m = "04"; d -= 31; }
if (d < 10) d = "0" + d;
// two series, one with range 1-100, one with range 1-2M
data.push([new Date("2010/" + m + "/" + d),
i,
100 - i,
1e6 * (1 + i * (100 - i) / (50 * 50)),
1e6 * (2 - i * (100 - i) / (50 * 50))]);
}
g = new Dygraph(
document.getElementById("demodiv"),
data,
{
labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
width: 640,
height: 350,
'Y3': {
axis: {
}
},
'Y4': {
axis: 'Y3' // use the same y-axis as series Y3
},
xAxisLabelWidth: 100,
yAxisLabelWidth: 100,
axes: {
x: {
valueFormatter: function(ms) {
return 'xvf(' + new Date(ms).strftime('%Y-%m-%d') + ')';
},
axisLabelFormatter: function(d) {
return 'xalf(' + d.strftime('%Y-%m-%d') + ')';
},
pixelsPerLabel: 100,
},
y: {
valueFormatter: function(y) {
return 'yvf(' + y.toPrecision(2) + ')';
},
axisLabelFormatter: function(y) {
return 'yalf(' + y.toPrecision(2) + ')';
}
},
y2: {
valueFormatter: function(y2) {
return 'y2vf(' + y2.toPrecision(2) + ')';
},
axisLabelFormatter: function(y2) {
return 'y2alf(' + y2.toPrecision(2) + ')';
}
}
}
}
);
</script>
</body>
</html>
Something went wrong with that request. Please try again.