mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 20:29:12 +02:00
Update line sample to test adding and removing datasets
This commit is contained in:
parent
19a30f5090
commit
e7850a796e
@ -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>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user