[Chartjs]-Chart.JS Global Options

7👍

When you do

var options = Chart.defaults.global = {
   ...

you are setting the COMPLETE Chart global default to your object. Unless you have ALL the Chart global options in your object, this will cause many of the options to end up as undefined. The right way to set the global options is like so

Chart.defaults.global.animation = true;
Chart.defaults.global.animationSteps = 160;
...

i.e. change the value of the individual properties in global instead of setting the entire global property.

0👍

Global options for charts can be set like this:

Chart.defaults.global = {
//Set options

So you can just delete the

var = options

This sets default values for all of your future charts

Please refer to the documentation for further instructions: http://www.chartjs.org/docs/

If you want to specify options for each charts do this:

new Chart(ctx).Line(data, {
    // options here
});

0👍

First it must be understood that the main property to be tweaked so as to handle the animations is “Chart.defaults.global.animation”.

Then keeping this as the base, you will need to adjust the sub-properties as mentioned above and in the documentation page.

So, You can change as follows:

Chart.defaults.global.animation.animationSteps=160;
Chart.defaults.global.animation.duration=5000;
...

For positioning of these lines of code, follow the first answer by potatopeelings.

I have tried changing in this way and it works !!!

Leave a comment