Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to set Global Options in Chart.js

I am using following code to set global options in Chart.js

Chart.defaults.global = {
    animationSteps: 30,
    tooltipCornerRadius: 0
}

var ctx = document.getElementById("canvas").getContext("2d");
    var LChart = new Chart(ctx).Line(data, {
});

It however gives me error

TypeError: fn is not a function

on line 499 in Chart.js

How can I resolve this issue?

like image 995
Sandip Patel Avatar asked Dec 24 '22 19:12

Sandip Patel


1 Answers

Instead of doing this

Chart.defaults.global = {
    animationSteps: 30,
    tooltipCornerRadius: 0
}

you should do this

Chart.defaults.global.animationSteps = 30;
Chart.defaults.global.tooltipCornerRadius = 0;

When you do the former, you are wiping out all the default values by putting in an entirely new global object (instead of just changing the properties you want to). The only way to get that to work would be define each and every property.

like image 164
potatopeelings Avatar answered Jan 09 '23 20:01

potatopeelings