Skip to content

Commit

Permalink
Fix : samples (line-stacked-area.html & step-size.html) (#3717)
Browse files Browse the repository at this point in the history
Fix : samples
line-stacked-area.html:Changed j-query code to javascript
step-size.html:Fixed buttons not working
  • Loading branch information
KoyoSE authored and etimberg committed Dec 18, 2016
1 parent 7756bed commit 64b5def
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
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

0 comments on commit 64b5def

Please sign in to comment.