2 <link rel=
"stylesheet" href=
"../css/dygraph.css">
3 <title>legendFormatter
</title>
12 display: inline-block;
17 <h2>legendFormatter
</h2>
18 <p>This page demonstrates use of
<a href=
"../options.html#legendFormatter"><code>legendFormatter
</code></a>, which can be used to create more complex legends than
<code>valueFormatter
</code>.
</p>
19 <div id=
"demodiv"></div>
20 <div id=
"legend"></div>
22 <script type=
"text/javascript" src=
"../dist/dygraph.js"></script>
23 <script type=
"text/javascript">
24 function legendFormatter(data) {
26 // This happens when there's no selection and {legend: 'always'} is set.
27 return '
<br>' + data.series.map(function(series) { return series.dashHTML + ' ' + series.labelHTML }).join('
<br>');
30 var html = this.getLabels()[
0] + ': ' + data.xHTML;
31 data.series.forEach(function(series) {
32 if (!series.isVisible) return;
33 var labeledData = series.labelHTML + ': ' + series.yHTML;
34 if (series.isHighlighted) {
35 labeledData = '
<b>' + labeledData + '
</b>';
37 html += '
<br>' + series.dashHTML + ' ' + labeledData;
43 document.getElementById(
"demodiv"),
45 var zp = function(x) { if (x <
10) return
"0"+x; else return x; };
46 var r =
"date,parabola,line,another line,sine wave\n";
47 for (var i=
1; i<=
31; i++) {
48 r +=
"200610" + zp(i);
49 r +=
"," +
10*(i*(
31-i));
51 r +=
"," +
10*(
250 -
8*i);
52 r +=
"," +
10*(
125 +
125 * Math.sin(
0.3*i));
58 labelsDiv: document.getElementById('status'),
60 colors: [
"rgb(51,204,204)",
63 "rgba(50,50,200,0.4)"],
64 title: 'Interesting Shapes',
67 highlightSeriesOpts: { strokeWidth:
2 },
68 labelsDiv: document.getElementById('legend'),
70 legendFormatter: legendFormatter