Update line sample to test adding and removing datasets

This commit is contained in:
Evert Timberg 2015-06-16 22:05:06 -04:00
parent 19a30f5090
commit e7850a796e

View File

@ -19,6 +19,8 @@
<br> <br>
<br> <br>
<button id="randomizeData">Randomize Data</button> <button id="randomizeData">Randomize Data</button>
<button id="addDataset">Add Dataset</button>
<button id="removeDataset">Remove Dataset</button>
<script> <script>
var randomScalingFactor = function() { var randomScalingFactor = function() {
return Math.round(Math.random() * 100 * (Math.random() > 0.5 ? -1 : 1)); return Math.round(Math.random() * 100 * (Math.random() > 0.5 ? -1 : 1));
@ -70,11 +72,28 @@
$('#randomizeData').click(function() { $('#randomizeData').click(function() {
config.data.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]; config.data.datasets[0].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
config.data.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]; config.data.datasets[1].data = [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()];
window.myLine.update(); window.myLine.update();
}); });
$('#addDataset').click(function() {
var newDataset = {
label: 'Dataset ' + config.data.datasets.length,
borderColor: randomColor(0.4),
backgroundColor: randomColor(0.5),
pointBorderColor: randomColor(0.7),
pointBackgroundColor: randomColor(0.5),
pointBorderWidth: 1,
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
};
window.myLine.addDataset(newDataset);
});
$('#removeDataset').click(function() {
window.myLine.removeDataset(0);
});
</script> </script>
</body> </body>