简体   繁体   English

我如何使用c3.js在javascript中制作图形

[英]how can i make a graph in javascript using c3.js

i am trying to make a graph in javascript using chart.js. 我试图使用chart.js在javascript中制作图形。 i have this code below but when i run it the page is empty. 我在下面有此代码,但是当我运行它时页面为空。 this code is an example that ive seen in the internet, and it says that it doesn't recognize the "generate" function in the javascrpt file (it doesnt throws an exception or an error, just marks the "generate" word in gray and doesn't shows anything when i run the code) 该代码是我在互联网上看到的一个示例,它说它无法识别javascrpt文件中的“生成”功能(它不会引发异常或错误,只是将“生成”字样标记为灰色,当我运行代码时不显示任何内容)

this is the html code: 这是html代码:

<!DOCTYPE html>
<html lang="en">


<head>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.10/c3.min.js"></script>
</head>
<body>
<div id ="myChart"></div>
<script><script src="lol.js"></script></script>
</body>
</html>

this is the js code: 这是js代码:

var chart = c3.generate({
    data: {
        columns: [
            ['data1', 30, 200, 100, 400, 150, 250],
            ['data2', 50, 20, 10, 40, 15, 25]
        ]
    }
});

setTimeout(function () {
    chart.load({
        columns: [
            ['data1', 230, 190, 300, 500, 300, 400]
        ]
    });
}, 1000);

setTimeout(function () {
    chart.load({
        columns: [
            ['data3', 130, 150, 200, 300, 200, 100]
        ]
    });
}, 1500);

setTimeout(function () {
    chart.unload({
        ids: 'data1'
    });
}, 2000);

how can i fix that? 我该如何解决? i need to make a graph to my project with javascript and i trying to find out a way how. 我需要用javascript为我的项目做一个图,我试图找出一种方法。 thanks! 谢谢!

You seem to be missing the bindto part of C3's initialization code: 您似乎缺少了C3初始化代码的bindto部分:

var chart = c3.generate({
  bindto: '#myChart',  // <---- here
  data: {
    columns: [
      ['data1', 30, 200, 100, 400, 150, 250],
      ['data2', 50, 20, 10, 40, 15, 25]
    ]
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM