From: Evert Timberg Date: Sun, 23 Aug 2015 17:20:43 +0000 (-0400) Subject: Category scale filter function will hide the grid line if `null` or `undefined` returned. X-Git-Tag: 2.0.0-alpha4~41^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1407%2Fhead;p=thirdparty%2FChart.js.git Category scale filter function will hide the grid line if `null` or `undefined` returned. --- diff --git a/docs/00-Getting-Started.md b/docs/00-Getting-Started.md index 83b3cf691..5aeac0a1b 100644 --- a/docs/00-Getting-Started.md +++ b/docs/00-Getting-Started.md @@ -403,6 +403,9 @@ The `userCallback` method may be useful when there are a lot of labels. The foll xAxes: [{ labels: { maxRotation: 0, // set maxRotation to 0 to turn off auto-rotation + + // Return an empty string to draw the grid line but hide the label + // Return `null` or `undefined` to hide the grid line userCallback: function(labelString, index) { return (index % 5 === 0) ? labelString : ''; } diff --git a/samples/line-x-axis-filter.html b/samples/line-x-axis-filter.html index 3b5b82f28..71a1b8844 100644 --- a/samples/line-x-axis-filter.html +++ b/samples/line-x-axis-filter.html @@ -55,7 +55,7 @@ display: true, labels: { userCallback: function(dataLabel, index) { - return index % 2 === 0 ? dataLabel : ''; + return index % 2 === 0 ? dataLabel : null; } } }], diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index d97699c1f..7912f8dcb 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -230,7 +230,8 @@ } helpers.each(this.labels, function(label, index) { - if (skipRatio > 1 && index % skipRatio > 0) { + // Blank labels + if ((skipRatio > 1 && index % skipRatio > 0) || (label === undefined || label === null)) { return; } var xLineValue = this.getPixelForValue(label, index, null, false); // xvalues for grid lines