mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 04:09:08 +02:00
Refactor data generation in scatter basic example (#5877)
Replace repeated function call with compact function, generateData
This commit is contained in:
parent
3cb2d7050e
commit
5797e03421
@ -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()
|
||||
}]
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user