UNPKG

dcos-dygraphs

Version:

dygraphs is a fast, flexible open source JavaScript charting library.

83 lines (74 loc) 2.04 kB
<!DOCTYPE html> <html> <head> <title>Series highlighting</title> <!-- For production (minified) code, use: <script type="text/javascript" src="dygraph-combined.js"></script> --> <script type="text/javascript" src="../dist/dygraph.js"></script> <style type='text/css'> .few .dygraph-legend > span.highlight { border: 1px solid grey; } .many .dygraph-legend > span { display: none; } .many .dygraph-legend > span.highlight { display: inline; } </style> </head> <body> <h2>Series highlighting demo</h2> <script type='text/javascript'> var getData = function(numSeries, numRows, isStacked) { var data = []; for (var j = 0; j < numRows; ++j) { data[j] = [j]; } for (var i = 0; i < numSeries; ++i) { var val = 0; for (var j = 0; j < numRows; ++j) { if (isStacked) { val = Math.random(); } else { val += Math.random() - 0.5; } data[j][i + 1] = val; } } return data; }; var makeGraph = function(className, numSeries, numRows, isStacked) { var div = document.createElement('div'); div.className = className; div.style.display = 'inline-block'; document.body.appendChild(div); var labels = ['x']; for (var i = 0; i < numSeries; ++i) { var label = '' + i; label = 's' + '000'.substr(label.length) + label; labels[i + 1] = label; } var g = new Dygraph( div, getData(numSeries, numRows, isStacked), { width: 480, height: 320, labels: labels.slice(), stackedGraph: isStacked, highlightCircleSize: 2, strokeWidth: 1, strokeBorderWidth: isStacked ? null : 1, highlightSeriesOpts: { strokeWidth: 3, strokeBorderWidth: 1, highlightCircleSize: 5, }, }); g.setSelection(false, 's005'); //console.log(g); }; makeGraph("few", 20, 50, false); makeGraph("few", 10, 20, true); makeGraph("many", 75, 50, false); makeGraph("many", 40, 50, true); </script> </body> </html>