Chartjs 2.0 Rotation

Asked

Viewed 77 times

1

How can I rotate the text?

What do I have: inserir a descrição da imagem aqui

I’m trying to rotate but the ctx.translate doesn’t work right, see:

inserir a descrição da imagem aqui

This is my code:

animation: {
                        onComplete: function () {
                            var chartInstance = this.chart;
                            var ctx = chartInstance.ctx;
                            ctx.textAlign = "center";
                            ctx.font = "bold 25px Arial";
                            ctx.fillStyle = "white";
                            ctx.translate(0,1000);
                            ctx.rotate(-0.5*Math.PI);
                            Chart.helpers.each(this.data.datasets.forEach(function (dataset, i) {
                                var meta = chartInstance.controller.getDatasetMeta(i);
                                Chart.helpers.each(meta.data.forEach(function (bar, index) {
                                    ctx.fillText(dataset.data[index], bar._model.x, bar._model.y - 36);
                                }),this)
                            }),this);
                        }
                    }

1 answer

2


Do you really need the caption? Because when you hover over each bar, the caption appears... Try to insert this configuration in the script:

 options: { 
         legend: 
                { 
                 display: false 
                } 
          }

So it will not be displayed initially, only when the mouse is passed over each bar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.