From 305ed6dc76b8c116c2386b798c543f5efd1eca41 Mon Sep 17 00:00:00 2001 From: Richard Lindner Date: Tue, 12 Apr 2016 11:10:51 +0200 Subject: [PATCH] Lightweight fix for unexpected category behavior when multiple series are used. Fixes #1643 --- src/data.convert.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/data.convert.js b/src/data.convert.js index 3c4da57..156109d 100644 --- a/src/data.convert.js +++ b/src/data.convert.js @@ -146,12 +146,20 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { id: convertedId, id_org: id, values: data.map(function (d, i) { - var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i), - value = d[id] !== null && !isNaN(d[id]) ? +d[id] : null; + var xKey = $$.getXKey(id), rawX = d[xKey], + value = d[id] !== null && !isNaN(d[id]) ? +d[id] : null, x; // use x as categories if custom x and categorized - if ($$.isCustomX() && $$.isCategorized() && index === 0 && rawX) { - if (i === 0) { config.axis_x_categories = []; } - config.axis_x_categories.push(rawX); + if ($$.isCustomX() && $$.isCategorized() && rawX) { + if (index === 0 && i === 0) { + config.axis_x_categories = []; + } + x = config.axis_x_categories.indexOf(rawX); + if (x === -1) { + x = config.axis_x_categories.length; + config.axis_x_categories.push(rawX); + } + } else { + x = $$.generateTargetX(rawX, id, i); } // mark as x = undefined if value is undefined and filter to remove after mapped if (isUndefined(d[id]) || $$.data.xs[id].length <= i) {