Browse Source

Fix loading json with undefined data - #325

pull/329/head
Masayuki Tanaka 11 years ago
parent
commit
645a034e04
  1. 4
      c3.js
  2. 2
      c3.min.js
  3. 28
      htdocs/samples/data_json.html

4
c3.js

@ -1499,7 +1499,9 @@
json.forEach(function (o) {
var new_row = [];
targetKeys.forEach(function (key) {
new_row.push(o[key]);
// convert undefined to null becuase undefined data will be removed in convertDataToTargets()
var v = typeof o[key] === 'undefined' ? null : o[key];
new_row.push(v);
});
new_rows.push(new_row);
});

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

28
htdocs/samples/data_json.html

@ -5,6 +5,7 @@
<body>
<div id="chart1"></div>
<div id="chart2"></div>
<div id="chart3"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
@ -43,6 +44,33 @@
}
});
var chart3 = c3.generate({
bindto: '#chart3',
data: {
json: [{
"date": "2014-06-03",
"443": "3000",
"995": "500"
}, {
"date": "2014-06-04",
"443": "1000",
}, {
"date": "2014-06-05",
"443": "5000",
"995": "1000"
}],
keys: {
x: 'date',
value: [ "443", "995" ]
}
},
axis: {
x: {
type: "category"
}
}
});
</script>
</body>
</html>

Loading…
Cancel
Save