Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/line/line-stacked-area.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
};

document.getElementById('randomizeData').addEventListener('click', function() {
$.each(config.data.datasets, function(i, dataset) {
config.data.datasets.forEach(function(dataset) {
dataset.data = dataset.data.map(function() {
return randomScalingFactor();
});
Expand Down
59 changes: 59 additions & 0 deletions samples/scales/linear/step-size.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,65 @@
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
};

document.getElementById('randomizeData').addEventListener('click', function() {
config.data.datasets.forEach(function(dataset) {
dataset.data = dataset.data.map(function() {
return randomScalingFactor();
});
});

window.myLine.update();
});

var colorNames = Object.keys(window.chartColors);
document.getElementById('addDataset').addEventListener('click', function() {
var colorName = colorNames[config.data.datasets.length % colorNames.length];
var newColor = window.chartColors[colorName];
var newDataset = {
label: 'Dataset ' + config.data.datasets.length,
backgroundColor: newColor,
borderColor: newColor,
data: [],
fill: false
};

for (var index = 0; index < config.data.labels.length; ++index) {
newDataset.data.push(randomScalingFactor());
}

config.data.datasets.push(newDataset);
window.myLine.update();
});

document.getElementById('addData').addEventListener('click', function() {
if (config.data.datasets.length > 0) {
var month = MONTHS[config.data.labels.length % MONTHS.length];
config.data.labels.push(month);

config.data.datasets.forEach(function(dataset) {
dataset.data.push(randomScalingFactor());
});

window.myLine.update();
}
});

document.getElementById('removeDataset').addEventListener('click', function() {
config.data.datasets.splice(0, 1);
window.myLine.update();
});

document.getElementById('removeData').addEventListener('click', function() {
config.data.labels.splice(-1, 1); // remove the label first

config.data.datasets.forEach(function(dataset, datasetIndex) {
dataset.data.pop();
});

window.myLine.update();
});

</script>
</body>

Expand Down