Chart.js: Polar Chart - Labels on the Polar chart

Created on 4 Feb 2018  路  3Comments  路  Source: chartjs/Chart.js

344 I want to display labels on the base of the sectors around the arc (like in picture 1). I went through #344 but couldn't find a solution to achieve this. Does latest chart.js support this feature?

image

image

Thanks in advance.

implement externally

Most helpful comment

I have one solution which is good for my problem which may also useful for you all.

first labels array which you want to show on top add in datasets property with key labels and then add below code to your options property

        hover: {
            animationDuration: 0
          },
        animation: {
            duration: 1,
            onComplete: function() {
              var chartInstance = this.chart,
                ctx = chartInstance.ctx;

              ctx.font = "15px Arial";
              ctx.textAlign = 'right';
              ctx.textBaseline = 'bottom';
              ctx.fillStyle = "#000";

              this.data.datasets.forEach(function(dataset, i) {
                var meta = chartInstance.controller.getDatasetMeta(i);
                meta.data.forEach(function(bar, index) {
                  var myangl=((bar._model.startAngle)+(bar._model.endAngle))/2;
                  var xpoint= (parseFloat(bar._model.outerRadius)+20)*(Math.cos(myangl)) + (bar._model.x);
                  var ypoint= (parseFloat(bar._model.outerRadius)+20)*(Math.sin(myangl)) + (bar._model.y);
                  ctx.fillText(bar._model.label,xpoint ,ypoint);
                });
              });
            }
          }

All 3 comments

I have one solution which is good for my problem which may also useful for you all.

first labels array which you want to show on top add in datasets property with key labels and then add below code to your options property

        hover: {
            animationDuration: 0
          },
        animation: {
            duration: 1,
            onComplete: function() {
              var chartInstance = this.chart,
                ctx = chartInstance.ctx;

              ctx.font = "15px Arial";
              ctx.textAlign = 'right';
              ctx.textBaseline = 'bottom';
              ctx.fillStyle = "#000";

              this.data.datasets.forEach(function(dataset, i) {
                var meta = chartInstance.controller.getDatasetMeta(i);
                meta.data.forEach(function(bar, index) {
                  var myangl=((bar._model.startAngle)+(bar._model.endAngle))/2;
                  var xpoint= (parseFloat(bar._model.outerRadius)+20)*(Math.cos(myangl)) + (bar._model.x);
                  var ypoint= (parseFloat(bar._model.outerRadius)+20)*(Math.sin(myangl)) + (bar._model.y);
                  ctx.fillText(bar._model.label,xpoint ,ypoint);
                });
              });
            }
          }

I need to add labels as well.
Can you give some help on how to implement this please?

here is a hack that I ended up with - radar has the labels so you can draw the"radar" behind "polar area". Just add two canvases one above the other and setup the radar so only the labels are visible (like transparent colors for the chart lines etc).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benmccann picture benmccann  路  3Comments

bytesnz picture bytesnz  路  3Comments

SylarRuby picture SylarRuby  路  3Comments

nickgoodliff picture nickgoodliff  路  3Comments

JAIOMP picture JAIOMP  路  3Comments