C3JS - 无法读取未定义的属性“category10" [英] C3JS - Cannot read property 'category10' of undefined

查看:13
本文介绍了C3JS - 无法读取未定义的属性“category10"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 jsfiddle (https://jsfiddle.net/varunoberoi/mcd6ucge) 尝试了这个 c3.js 代码,但它没有似乎在我的本地主机中不起作用.

I tried this c3.js code from jsfiddle (https://jsfiddle.net/varunoberoi/mcd6ucge) but it doesn't seem to work in my localhost.

我使用 uniserver 作为我的服务器.我复制粘贴所有内容,但它不起作用.

I'm using uniserver as my server. I copy-paste everything but it's not working.

<html>
    <head>
        <!-- CSS -->
        <link href="css/c3.css" rel="stylesheet" type="text/css" />

        <!-- JAVASCRIPT -->
        <script src="js/d3.min.js" type="text/javascript"></script>
        <script src="js/c3.js" type="text/javascript"></script>

        <script type="text/javascript">
            window.onload=function(){
                var chart = c3.generate({
                    data: {
                        columns: [
                            ['data1', 300, 350, 300, 0, 0, 0],
                            ['data2', 130, 100, 140, 200, 150, 50]
                        ],
                        types: {
                            data1: 'area',
                            data2: 'area-spline'
                        }
                    },
                    axis: {
                        y: {
                            padding: {bottom: 0},
                            min: 0
                        },
                        x: {
                            padding: {left: 0},
                            min: 0,
                            show: false
                        }
                    }

                });
            }
        </script>
    </head>
    <body>
        <div id="chart"></div>
    </body>
</html>

当我检查开发者工具的控制台时,我得到的是:

What I got when I check the Developer Tools' console is this:

c3.js:5783 Uncaught TypeError: Cannot read property 'category10' of undefined

我尝试了不同版本的 c3.js,但一无所获.这很奇怪,因为它在 jsfiddle 中工作,而不是在我的本地工作.

I tried different versions of c3.js but nothing. It's weird because it's working in jsfiddle and not in my local.

推荐答案

我通过从 D3.js v4 (4.1.1) 降级到 v3 (3.5.17) 解决了另一个项目中完全相同的 JavaScript 错误.

I solved the exact same JavaScript error on another project by downgrading from D3.js v4 (4.1.1) to v3 (3.5.17).

事实证明,截至 2016 年 7 月,C3.js 不支持 D3.js v4:

It turns out that C3.js, as of July 2016, does not support D3.js v4:

它肯定不会在 [D3.js] 4.0 中正常工作.D3 v4 具有完全不同的命名空间,并且绝不向后兼容.更新到 v4 是一项非常重要的任务.

It definitely will not work as-is with [D3.js] 4.0. D3 v4 has a totally different namespace and is in no way backwards compatible. Updating to v4 is a very non-trivial task.

这篇关于C3JS - 无法读取未定义的属性“category10"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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