Skip to content

Commit 6f99157

Browse files
martinzuernetimberg
authored andcommitted
Fixed misplaced data points on category scale
* Fixed issue, that category scale shows data points misplaced. See #4060 * Cleaned code * Fixed Irregular whitespace * Fixed error in case value is undefined * Verified that no error is thrown in case value === null
1 parent f3816b5 commit 6f99157

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/scales/scale.category.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ module.exports = function(Chart) {
6666
// 1 is added because we need the length but we have the indexes
6767
var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
6868

69-
if (value !== undefined && isNaN(index)) {
69+
// If value is a data object, then index is the index in the data array,
70+
// not the index of the scale. We need to change that.
71+
var valueCategory;
72+
if (value !== undefined && value !== null) {
73+
valueCategory = me.isHorizontal() ? value.x : value.y;
74+
}
75+
if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
7076
var labels = me.getLabels();
77+
value = valueCategory || value;
7178
var idx = labels.indexOf(value);
7279
index = idx !== -1 ? idx : index;
7380
}

0 commit comments

Comments
 (0)