-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[BUG] Can't update scale.ticks.* options at runtime since 2.7.0 #4896
Comments
It seems that v.2.7.0 uses the |
It worked for me thanks a lot! I had the same issue with The docs tell that if they are not specified , |
@simonbrunel I might be mistaken, however it seems that PR #4198, actually fixed this bug by recreating the scales on update. |
That would need to be tested but I don't think #4198 fixes that issue: scale options are not generated but fetched from the Ideally, Though, I think that would be a breaking change since |
Not tested but what we could do in Chart.Scale = Element.extend({
initialize: function() {
// initialize is called from the Element constructor
this._update();
},
/**
* Called by the chart controller on update()
* @private
*/
_update: function(options) {
// Note: keep this.options valid for backward compatibility
this.options = options;
this._config = this._configure(options);
},
/**
* @private
*/
_configure: function(options) {
// Let's first clone `options` which is probably a reference
// on the user options and should not be modified internally
// https://github.com/chartjs/Chart.js/issues/4896
var config = helpers.clone(options);
var ticks = config.ticks;
// ... resolve config.ticks.minor / config.ticks.major ...
return config;
}
}) Then replace all uses of And in scale = scales[id];
scale.ctx = me.ctx; //< not sure why it's needed
scale.chart = me; //< not sure why it's needed
scale._update(item.options)
// ... |
@simonbrunel Exactly the scale options are fetched from |
I can't get it work with master: https://jsfiddle.net/25q2k47z/ (maybe I misunderstood the original issue). So I'm not sure the following case is resolved: var chart = new Chart(ctx, {
options: {
scales: {
xAxes: [{
ticks: {
fontSize: 42
}
}]
}
}
});
// ...
chart.options.scales.xAxes[0].ticks.fontSize = 12;
chart.update(); |
I see what you mean, I tested the original fiddle, which hasn't got the |
@simonbrunel I like your proposal to introduce a private configuration variable Also I see we currently have a |
The idea behind my proposal is to store an intermediary state ( We can still do a deep copy of
Backward compatibility, we can't change their behavior until v3 (for which I would remove |
If you look at this jsfiddle: http://jsfiddle.net/jmpxgufu/179/
I put together a small bar chart, and on an interval (after 5 seconds), it will update some fontSizes and labels on the y-axis. Yet, the tick fontSize won't update (but everything else will).
I am pointing to https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.bundle.min.js (or if you try to point here: http://www.chartjs.org/dist/2.7.0/Chart.bundle.js, it fails as well, it doesn't matter either way -- here's a jsfiddle using that lib: http://jsfiddle.net/jmpxgufu/183/)
I had stolen this jsfiddle from someone and modified it to fit my needs. Previously they were using 2.4.0, and it worked with that library. Did something break between 2.4.0 and 2.7.0?
The text was updated successfully, but these errors were encountered: