dygraphs
Version:
dygraphs is a fast, flexible open source JavaScript charting library.
95 lines (89 loc) • 3.27 kB
HTML
<html>
<head>
<meta charset="UTF-8">
<title>valueFormatter and axisLabelFormatter</title>
<link rel="stylesheet" type="text/css" href="../dist/dygraph.css" />
<link rel="stylesheet" type="text/css" href="../common/vextlnk.css" />
<script type="text/javascript" src="../dist/dygraph.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"><!--//--><![CDATA[//><!--
Dygraph.onDOMready(function onDOMready() {
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))]);
}
function formatDate(d) {
var yyyy = d.getFullYear(),
mm = d.getMonth() + 1,
dd = d.getDate();
return yyyy + '-' + (mm < 10 ? '0' : '') + mm + (dd < 10 ? '0' : '') + dd;
}
g = new Dygraph(
document.getElementById("demodiv"),
data,
{
labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ],
width: 640,
height: 350,
series: {
'Y3': { axis: 'y2' },
'Y4': { axis: 'y2' }
},
axes: {
x: {
valueFormatter: function(ms) {
return 'xvf(' + formatDate(new Date(ms)) + ')';
},
axisLabelFormatter: function(d) {
return 'xalf(' + formatDate(d) + ')';
},
pixelsPerLabel: 100,
axisLabelWidth: 100,
},
y: {
valueFormatter: function(y) {
return 'yvf(' + y.toPrecision(2) + ')';
},
axisLabelFormatter: function(y) {
return 'yalf(' + y.toPrecision(2) + ')';
},
axisLabelWidth: 100
},
y2: {
valueFormatter: function(y2) {
return 'y2vf(' + y2.toPrecision(2) + ')';
},
axisLabelFormatter: function(y2) {
return 'y2alf(' + y2.toPrecision(2) + ')';
}
}
}
}
);
});
//--><!]]></script>
</body>
</html>