Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

360
Views
Legend position is not vertically in middle in Donut chart

In Donut chart Legend position is right but i want to add vertically in middle with corresponding of circle.

I am new to chartjs and JavaScript. Below is my code snippet. I am trying to load the pie/donut chart with legends but position is not right

// chart colors 
var colors = ['#007bff', '#28a745', '#333333', '#c3e6cb'];
var donutOptions = {
  cutoutPercentage: 65,
  responsive: true,

  legend: {
    position: 'right',
    padding: 2,
    labels: {
      pointStyle: 'circle',
      usePointStyle: true,
    }
  }
};
// donut 1
var chDonutData1 = {
  labels: ['Product 1', 'Product 2', 'Product 3', 'Product 4'],
  datasets: [{
    backgroundColor: colors.slice(0, 4),
    borderWidth: 2,
    data: [74, 11, 40, 20]
  }],


};

var chDonut1 = document.getElementById("chDonut1");
if (chDonut1) {
  new Chart(chDonut1, {
    type: 'pie',
    data: chDonutData1,
    options: donutOptions
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.js"></script>

<div class="">
  <canvas id="chDonut1"></canvas>
</div>

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Updating to the latest V2 (2.9.4) version of chart.js will resolve your issue:

// chart colors 
var colors = ['#007bff', '#28a745', '#333333', '#c3e6cb'];
var donutOptions = {
  cutoutPercentage: 65,
  responsive: true,

  legend: {
    position: 'right',
    padding: 2,
    labels: {
      pointStyle: 'circle',
      usePointStyle: true,
    }
  }
};
// donut 1
var chDonutData1 = {
  labels: ['Product 1', 'Product 2', 'Product 3', 'Product 4'],
  datasets: [{
    backgroundColor: colors.slice(0, 4),
    borderWidth: 2,
    data: [74, 11, 40, 20]
  }],


};

var chDonut1 = document.getElementById("chDonut1");
if (chDonut1) {
  new Chart(chDonut1, {
    type: 'pie',
    data: chDonutData1,
    options: donutOptions
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>

<div class="">
  <canvas id="chDonut1"></canvas>
</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!