Skip to content

Commit

Permalink
Refactor data generation in scatter basic example (#5877)
Browse files Browse the repository at this point in the history
Replace repeated function call with compact function, generateData
  • Loading branch information
generic-github-user authored and simonbrunel committed Dec 4, 2018
1 parent 3cb2d70 commit 5797e03
Showing 1 changed file with 13 additions and 44 deletions.
57 changes: 13 additions & 44 deletions samples/charts/scatter/basic.html
Expand Up @@ -21,59 +21,28 @@
<button id="randomizeData">Randomize Data</button>
<script>
var color = Chart.helpers.color;
function generateData() {
var data = [];
for (var i = 0; i < 7; i++) {
data.push({
x: randomScalingFactor(),
y: randomScalingFactor()
});
}
return data;
}

var scatterChartData = {
datasets: [{
label: 'My First dataset',
borderColor: window.chartColors.red,
backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
data: [{
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}]
data: generateData()
}, {
label: 'My Second dataset',
borderColor: window.chartColors.blue,
backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
data: [{
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}, {
x: randomScalingFactor(),
y: randomScalingFactor(),
}]
data: generateData()
}]
};

Expand Down

0 comments on commit 5797e03

Please sign in to comment.