Commit d074ef8a authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix timeseries data loading

parent 951a78ac
...@@ -1253,7 +1253,7 @@ ...@@ -1253,7 +1253,7 @@
function generateTargetX(rawX, id, index) { function generateTargetX(rawX, id, index) {
var x; var x;
if (isTimeSeries) { if (isTimeSeries) {
x = rawX ? rawX instanceof Date ? rawX : parseDate(rawX) : null; x = rawX ? rawX instanceof Date ? rawX : parseDate(rawX) : parseDate(getXValue(id, index));
} }
else if (isCustomX && !isCategorized) { else if (isCustomX && !isCategorized) {
x = rawX ? +rawX : getXValue(id, index); x = rawX ? +rawX : getXValue(id, index);
...@@ -1290,15 +1290,10 @@ ...@@ -1290,15 +1290,10 @@
function convertDataToTargets(data) { function convertDataToTargets(data) {
var ids = d3.keys(data[0]).filter(isNotX), xs = d3.keys(data[0]).filter(isX), targets; var ids = d3.keys(data[0]).filter(isNotX), xs = d3.keys(data[0]).filter(isX), targets;
// check "x" is defined if timeseries
if (isTimeSeries && xs.length === 0) {
throw new Error('data.x or data.xs must be specified when axis.x.type == "timeseries"');
}
// save x for update data by load when custom x and c3.x API // save x for update data by load when custom x and c3.x API
ids.forEach(function (id) { ids.forEach(function (id) {
var xKey = getXKey(id); var xKey = getXKey(id);
if (isCustomX) { if (isCustomX || isTimeSeries) {
if (xs.indexOf(xKey) >= 0) { if (xs.indexOf(xKey) >= 0) {
c3.data.x[id] = data.map(function (d) { return d[xKey]; }); c3.data.x[id] = data.map(function (d) { return d[xKey]; });
} }
......
...@@ -30,6 +30,25 @@ ...@@ -30,6 +30,25 @@
} }
} }
}); });
setTimeout(function () {
chart.load({
columns: [
['sample', 200, 130, 90, 240, 130, 100],
['sample2', 300, 200, 160, 400, 250, 250]
]
});
}, 1000);
setTimeout(function () {
chart.load({
columns: [
['date', '20140101', '20140201', '20140301', '20140401', '20140501', '20140601'],
['sample', 500, 630, 690, 440, 630, 900],
['sample2', 400, 600, 460, 200, 350, 450]
]
});
}, 2000);
</script> </script>
</body> </body>
</html> </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