I am using chart.js.
Similar to this Question, I would like to rotate my x-axis labels 90 degrees. Currently my labels are rotated about 80 degrees with default settings.
Could somebody help me adapt the bar-chart solution for rotating labels, so that I can use it on line-charts?
Rotate X-Axis Tick Labels in Matplotlib There are two ways to go about it - change it on the Figure-level using plt. xticks() or change it on an Axes-level by using tick. set_rotation() individually, or even by using ax.
Change Text Direction Using A Text Box Select the text orientation you need and select okay. b) left click inside the text box, then right click, and select “Borders and Alignment” from the options that appear. Select the text orientation you need and select okay.
In the Select Data Source dialog box, under Horizontal (Categories) Axis Labels, click Edit. In the Axis label range box, do one of the following: Specify the worksheet range that you want to use as category axis labels. , and then select the range that you want to use on the worksheet.
If you are using chart.js 2.x, just set maxRotation: 90
and minRotation: 90
in ticks options. It works for me! And if you want to all x-labels, you may want to set autoSkip: false
. The following is an example.
var myChart = new Chart(ctx, { type: 'bar', data: chartData, options: { scales: { xAxes: [{ ticks: { autoSkip: false, maxRotation: 90, minRotation: 90 } }] } } });
for x axis use this
options: { legend: { display: false }, scales: { xAxes: [ { ticks: { autoSkip: false, maxRotation: 0, minRotation: 0 } } ] } }
and can filter the label with a for
loop:
arrayLabels.forEach((date, i) => { let label = ""; if (i % step == 0 && fecha) { label = moment(date, "DD/MM").format("DD MMM"); } labels.push(label); }); chartOptions.data.labels = labels;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With