Commit de322408 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Support json as input - #236

parent 4bfe25de
......@@ -1453,6 +1453,13 @@
}
return x;
}
function convertJsonToData(json) {
var keys = Object.keys(json), new_rows = [];
keys.forEach(function (key) {
new_rows.push([key].concat(json[key]));
});
return convertColumnsToData(new_rows);
}
function convertRowsToData(rows) {
var keys = rows[0], new_row = {}, new_rows = [], i, j;
for (i = 1; i < rows.length; i++) {
......@@ -5054,7 +5061,7 @@
/*-- Load data and init chart with defined functions --*/
if ('url' in config.data) {
if (config.data.url) {
d3.xhr(config.data.url, function (error, data) {
// TODO: other mine/type
var rows = d3.csv.parseRows(data.response), d;
......@@ -5069,10 +5076,13 @@
init(d);
});
}
else if ('rows' in config.data) {
else if (config.data.json) {
init(convertJsonToData(config.data.json));
}
else if (config.data.rows) {
init(convertRowsToData(config.data.rows));
}
else if ('columns' in config.data) {
else if (config.data.columns) {
init(convertColumnsToData(config.data.columns));
}
else {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
<html>
<head>
<link href="/css/c3.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
var chart = c3.generate({
data: {
json: {
data1: [30, 20, 50, 40, 60, 50],
data2: [200, 130, 90, 240, 130, 220],
data3: [300, 200, 160, 400, 250, 250]
}
}
});
</script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment