Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove x-axis label/text in chart.js

How do I hide the x-axis label/text that is displayed in chart.js ?

Setting scaleShowLabels:false only removes the y-axis labels.

<script>     var options = {         scaleFontColor: "#fa0",         datasetStrokeWidth: 1,         scaleShowLabels : false,         animation : false,         bezierCurve : true,         scaleStartValue: 0,     };     var lineChartData = {         labels : ["1","2","3","4","5","6","7"],         datasets : [             {                 fillColor : "rgba(151,187,205,0.5)",                 strokeColor : "rgba(151,187,205,1)",                 pointColor : "rgba(151,187,205,1)",                 pointStrokeColor : "#fff",                 data : [1,3,0,0,6,2,10]             }         ]      }  var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData,options);  </script> 
like image 300
Sonny G Avatar asked May 02 '14 08:05

Sonny G


People also ask

How do I get rid of x-axis labels?

To hide or remove X-axis labels, use set(xlabel=None). To display the figure, use show() method.

How do you remove axis labels from chart?

Procedure. Select the axis chart object. To show or hide the axis labels, in the Properties pane, select or clear the Axis label check box.

How do I customize the x-axis labels?

Right-click the category labels you want to change, and click Select Data. In the Horizontal (Category) Axis Labels box, click Edit. In the Axis label range box, enter the labels you want to use, separated by commas.

How do I remove the x-axis labels in Excel?

To remove an axis title, on the Layout tab, in the Labels group, click Axis Title, click the type of axis title that you want to remove, and then click None. To quickly remove a chart or axis title, click the title, and then press DELETE. You can also right-click the chart or axis title, and then click Delete.


1 Answers

UPDATE chart.js 2.1 and above

var chart = new Chart(ctx, {     ...     options:{         scales:{             xAxes: [{                 display: false //this will remove all the x-axis grid lines             }]         }     } });   var chart = new Chart(ctx, {     ...     options: {         scales: {             xAxes: [{                 ticks: {                     display: false //this will remove only the label                 }             }]         }     } }); 

Reference: chart.js documentation

Old answer (written when the current version was 1.0 beta) just for reference below:

To avoid displaying labels in chart.js you have to set scaleShowLabels : false and also avoid to pass the labels:

<script>     var options = {         ...         scaleShowLabels : false     };     var lineChartData = {         //COMMENT THIS LINE TO AVOID DISPLAYING THE LABELS         //labels : ["1","2","3","4","5","6","7"],         ...      }     ... </script> 
like image 104
giammin Avatar answered Sep 20 '22 15:09

giammin