Skip to content

Instantly share code, notes, and snippets.

@ao
Created October 17, 2014 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ao/21eaf78b47e28ab65363 to your computer and use it in GitHub Desktop.
Save ao/21eaf78b47e28ab65363 to your computer and use it in GitHub Desktop.
ChartJS - hide x-labels
If you want to hide the labels when there are too many, you can use the following extension. It just pushes the x-labels off the canvas so they are painted but not visible.
Chart.types.Line.extend({
name : "AltLine",
initialize : function(data) {
Chart.types.Line.prototype.initialize.apply(this, arguments);
this.scale.draw = function() {
if (this.display && (this.xLabelRotation > 90)) {
this.endPoint = this.height - 5;
}
Chart.Scale.prototype.draw.apply(this, arguments);
};
}
});
// then
new Chart(ctx).AltLine(data, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment