Created
May 26, 2015 18:35
-
-
Save kberg/569a31ee597da86f5317 to your computer and use it in GitHub Desktop.
Series highlighting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript" src="http://dygraphs.com/dygraph-combined-dev.js"></script> | |
<style type='text/css'> | |
body { margin-top: 20px; margin-left: 20px; } | |
.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> | |
<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: 450, | |
height: 220, | |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment