Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update time combo sample #6736

Merged
merged 1 commit into from
Nov 13, 2019
Merged
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
61 changes: 19 additions & 42 deletions samples/scales/time/combo.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,45 @@
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
<script>
var timeFormat = 'MM/DD/YYYY HH:mm';
function newDate(days) {
return moment().startOf('day').add(days, 'd').valueOf();
}

function newDateString(days) {
return moment().add(days, 'd').format(timeFormat);
var labels = [];
var data1 = [];
var data2 = [];
var data3 = [];
for (var i = 0; i < 7; i++) {
labels.push(newDate(i));
data1.push(randomScalingFactor());
data2.push(randomScalingFactor());
data3.push(randomScalingFactor());
}

var color = Chart.helpers.color;
var config = {
type: 'bar',
data: {
labels: [
newDateString(0),
newDateString(1),
newDateString(2),
newDateString(3),
newDateString(4),
newDateString(5),
newDateString(6)
],
labels: labels,
datasets: [{
type: 'bar',
label: 'Dataset 1',
backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),
borderColor: window.chartColors.red,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
data: data1,
}, {
type: 'bar',
label: 'Dataset 2',
backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(),
borderColor: window.chartColors.blue,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
data: data2,
}, {
type: 'line',
label: 'Dataset 3',
backgroundColor: color(window.chartColors.green).alpha(0.5).rgbString(),
borderColor: window.chartColors.green,
fill: false,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
data: data3,
}]
},
options: {
Expand All @@ -99,9 +76,9 @@
xAxes: [{
type: 'time',
display: true,
offset: true,
time: {
format: timeFormat,
// round: 'day'
unit: 'day'
}
}],
},
Expand Down Expand Up @@ -145,7 +122,7 @@

document.getElementById('addData').addEventListener('click', function() {
if (config.data.datasets.length > 0) {
config.data.labels.push(newDateString(config.data.labels.length));
config.data.labels.push(newDate(config.data.labels.length));

for (var index = 0; index < config.data.datasets.length; ++index) {
config.data.datasets[index].data.push(randomScalingFactor());
Expand Down