Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  137] [ 5]  / answers: 1 / hits: 17624  / 8 Years ago, wed, july 13, 2016, 12:00:00

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



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


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


More From » d3.js

 Answers
22

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



It turns out that C3.js, as of July 2016, does not support D3.js 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.



[#61395] Monday, July 11, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kourtney

Total Points: 368
Total Questions: 103
Total Answers: 85

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
kourtney questions
Sun, Oct 4, 20, 00:00, 4 Years ago
Tue, Oct 29, 19, 00:00, 5 Years ago
Thu, Apr 4, 19, 00:00, 5 Years ago
Fri, Mar 1, 19, 00:00, 5 Years ago
;