无法在Chart.js中设置全局选项 [英] Unable to set Global Options in Chart.js

查看:89
本文介绍了无法在Chart.js中设置全局选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在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, {
});

但它给了我错误

TypeError: fn is not a function

。 js

如何解决此问题?

推荐答案

而不是这样做

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

你应该这样做

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.

这篇关于无法在Chart.js中设置全局选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆