Merge pull request #1929 from nnnick/fix/1917

Ensure that adding datasets to charts with time scales works
This commit is contained in:
Evert Timberg 2016-01-21 22:04:31 -05:00
commit 888379ec5c
2 changed files with 14 additions and 10 deletions

View File

@ -74,6 +74,7 @@
}, ] }, ]
}, },
options: { options: {
showLines: true,
responsive: true, responsive: true,
scales: { scales: {
xAxes: [{ xAxes: [{
@ -144,10 +145,7 @@
$('#addData').click(function() { $('#addData').click(function() {
if (config.data.datasets.length > 0) { if (config.data.datasets.length > 0) {
config.data.labels.push( config.data.labels.push(newDateString(config.data.labels.length));
myLine.scales['x-axis-0'].labelMoments[myLine.scales['x-axis-0'].labelMoments.length - 1].add(1, 'day')
.format('MM/DD/YYYY')
);
for (var index = 0; index < config.data.datasets.length; ++index) { for (var index = 0; index < config.data.datasets.length; ++index) {
config.data.datasets[index].data.push(randomScalingFactor()); config.data.datasets[index].data.push(randomScalingFactor());

View File

@ -208,8 +208,10 @@
Chart.layoutService.update(this, this.chart.width, this.chart.height); Chart.layoutService.update(this, this.chart.width, this.chart.height);
}, },
buildOrUpdateControllers: function buildOrUpdateControllers(resetNewControllers) { buildOrUpdateControllers: function buildOrUpdateControllers() {
var types = []; var types = [];
var newControllers = [];
helpers.each(this.data.datasets, function(dataset, datasetIndex) { helpers.each(this.data.datasets, function(dataset, datasetIndex) {
if (!dataset.type) { if (!dataset.type) {
dataset.type = this.config.type; dataset.type = this.config.type;
@ -222,10 +224,7 @@
dataset.controller.updateIndex(datasetIndex); dataset.controller.updateIndex(datasetIndex);
} else { } else {
dataset.controller = new Chart.controllers[type](this, datasetIndex); dataset.controller = new Chart.controllers[type](this, datasetIndex);
newControllers.push(dataset.controller);
if (resetNewControllers) {
dataset.controller.reset();
}
} }
}, this); }, this);
@ -237,6 +236,8 @@
} }
} }
} }
return newControllers;
}, },
resetElements: function resetElements() { resetElements: function resetElements() {
@ -250,10 +251,15 @@
this.tooltip._data = this.data; this.tooltip._data = this.data;
// Make sure dataset controllers are updated and new controllers are reset // Make sure dataset controllers are updated and new controllers are reset
this.buildOrUpdateControllers(true); var newControllers = this.buildOrUpdateControllers();
Chart.layoutService.update(this, this.chart.width, this.chart.height); Chart.layoutService.update(this, this.chart.width, this.chart.height);
// Can only reset the new controllers after the scales have been updated
helpers.each(newControllers, function(controller) {
controller.reset();
});
// Make sure all dataset controllers have correct meta data counts // Make sure all dataset controllers have correct meta data counts
helpers.each(this.data.datasets, function(dataset, datasetIndex) { helpers.each(this.data.datasets, function(dataset, datasetIndex) {
dataset.controller.buildOrUpdateElements(); dataset.controller.buildOrUpdateElements();