Browse Source

Fix timeseries data loading

pull/110/head
Masayuki Tanaka 11 years ago
parent
commit
d074ef8adc
  1. 9
      c3.js
  2. 2
      c3.min.js
  3. 19
      htdocs/samples/timeseries.html

9
c3.js

@ -1253,7 +1253,7 @@
function generateTargetX(rawX, id, index) {
var x;
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) {
x = rawX ? +rawX : getXValue(id, index);
@ -1290,15 +1290,10 @@
function convertDataToTargets(data) {
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
ids.forEach(function (id) {
var xKey = getXKey(id);
if (isCustomX) {
if (isCustomX || isTimeSeries) {
if (xs.indexOf(xKey) >= 0) {
c3.data.x[id] = data.map(function (d) { return d[xKey]; });
}

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

19
htdocs/samples/timeseries.html

@ -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>
</body>
</html>

Loading…
Cancel
Save