The inner radius remains constant in the Chart.js Doughnut Chart

I've been trying to create a half doughnut chart using Chart.js, similar to the image linked below. However, I'm having trouble adjusting the thickness of the pie chart. Despite using the innerRadius property, it's not producing the desired effect.

https://i.sstatic.net/9W34o.jpg

Below is the code I am currently using:

public getHalfDoughnutChart(records) {
    let data = {
       labels: ["Worked Hours","Remaining Hours"],
       datasets: [{
       label: 'Today\'s Worked Hours',
       data: [records.length ? records[0].duration.hour : 0, 9],
       backgroundColor: [
          'rgba(75, 174, 79, 1)',
          'rgba(255, 255, 255, 0)'
       ]
     }]
 };

    let options = {
      circumference: Math.PI,
      rotation: 1.0 * Math.PI,
      innerRadius: "10%",
      legend: {
        display: false
      },
      layout:{
        padding:40
      }, 
    }

     return this.getChart(this.halfDoughnutCanvas.nativeElement, "doughnut", data, options);
  }



getChart(context, chartType, data, options?) {
   return new Chart(context, {
      type: chartType,
      data: data,
      options: options
   });
}

Answer №1

To adjust the thickness of your doughnut chart, make sure to include the percentageInnerCutout property within the options object.

let options = {
  circumference: Math.PI,
  rotation: 1.0 * Math.PI,
  percentageInnerCutout: 10,
  legend: {
    display: false
  },
  layout:{
    padding:40
  }, 
}

If you need more information on this topic, check out this related question How to vary the thickness of doughnut chart using ChartJs?

Important! The method used may vary depending on the Chart.js version:

If using Chart.js version > 2.0, use cutoutPercentage

For older versions, utilize percentageInnerCutout

Answer №3

To customize the inner radius of a Doughnut Chart, you have the option to adjust the cutout setting.

options: {
    cutout: 30, // Specify cutout in pixels
}

Alternatively, you can also specify the cutout value in percentage as shown below:

options: {
    cutout: "30%", // Specify cutout in percentage
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to selectively display specific columns when outputting JSON to a dynamic HTML table?

I'm looking to output specific JSON data in an HTML table with JavaScript. The headers will remain the same, but the JSON content will vary. Currently, I have a working function that generates the entire table using JavaScript: <body> ...

Mastering the use of node cluster mode in conjunction with agenda cronjobs

Currently, I am utilizing nodejs and agenda to run cronjobs. With a total of 10 cronjobs in place, the process is taking longer as nodejs is single-threaded and they all run simultaneously. In an attempt to resolve this issue, I experimented with pm2 by e ...

Update the input value following a successful action

How can I update the value of an input field after a successful ajax call? I have tried the following approach but it doesn't seem to be working. The result from the alert is 80000 Here is the HTML input code: <input class="form-control" type=" ...

Scraping data from the web using R and creating interactive plots with hover text in Plotly without

I'm attempting to extract hover text content from plotly traces that have been shared online. This is a new type of scraping for me, and I'm exploring ways to accomplish this task in R without relying on selenium or phantomjs, possibly with the u ...

The problem arises when Angular's $interval function is not recognized

Despite the possibility of this being considered a duplicate, none of the related topics have provided a solution to my simple date count down directive: class Clock { constructor() { this.restrict = 'AC'; this.replace = true ...

The distance calculation is not functioning properly within the for loop

I am currently working on developing a geolocation test app. After finding some useful code for calculating the distance between two points using latitude and longitude coordinates, I am attempting to create a loop using a for loop to calculate the distan ...

Achieving a perfect circle can be accomplished by setting both the width and height to the same

Trying to make the height of an element equal to its width For example, aiming for a perfect circle Although the console displays equal values, the resulting height is noticeably greater than the width $('button').on('click', funct ...

Codeigniter code to retrieve dynamic data in a select box

I am trying to implement a functionality where selecting an option from one dropdown will dynamically populate the options in another dropdown based on the selection. I believe I need to use an onchange function, but I'm unsure how to retrieve data fr ...

Managing a secure login page with Protractor

Our team is currently exploring how to implement AngularJs and Polymer components in a new web application. I am tasked with creating a UI automation suite for this project. After conducting extensive research, it seems that Protractor could be the right t ...

Tips for validating forms within a modal that includes tabs using angularJs

I have a modal form in angular with uib-tabset that includes tabs for forms A, B, and C within the footer section of the modal. However, I am facing an issue where I cannot access the forms to enable/disable the save button on the footer. The forms appear ...

Using $watch to monitor the existence of a variable within the AngularJS scope

I'm working on a directive that displays alerts, and I want to set up a timeout function to run whenever the 'show' variable changes. How can I achieve this? When I tried invoking the link function, all the variables - show, message, and ty ...

What is the best way to display ng-repeat elements in a horizontal layout

Looking for a way to display thumbnails horizontally using ng-repeat in AngularJS and Bootstrap. Any ideas on how to achieve this with CSS or Bootstrap? <div class="row"> <ul class="col-md-4" id="phones"> <li class="thumbnail" ...

I encountered an error stating that ".then" is not defined during my attempt to save

Just starting out with node.js and I encountered an issue: TypeError: Cannot read property 'then' of undefined This is the code snippet causing the problem: router.post("/signup", (req, res) => { const userRegister = new UserRegister({ ...

Best practices for including jQuery in ASP.NET (or any other external JavaScript libraries)

Can you explain the distinctions among these three code samples below? Is there a preferred method over the others, and if so, why? 1.Page.ClientScript.RegisterClientScriptInclude(typeof(demo), "jQuery", Re ...

Evaluating the compatibility of AngularJS using the Selenium testing

I am currently working on a single-page application using ASP MVC and AngularJS, and I am looking for ways to test the UI. Right now, I am experimenting with Selenium along with PhantomJS and WebKit drivers. On one of my testing pages, there is a list of ...

Can a single value be stored in a table using a radio button?

I have created an HTML table that is dynamically generated from a database. I am using a for loop to populate the table. However, I am facing an issue where each radio button in the table holds only one value. What I actually want is for each row to have ...

Manage numerous canvas animations

Is there a way to interact with an already drawn Canvas animation? I am attempting to create 3 distinct tracks that can be controlled by a "Start" and "Stop" button. However, when I click the Start button on the first canvas, it triggers the last canvas in ...

Best practices for incorporating and leveraging node packages with Laravel Mix

As I embark on my Laravel (v 8.x) Mix project, I am encountering challenges when it comes to incorporating JavaScript from node modules. To kick things off, here is a snippet from my webpack.mix.js: mix.js('node_modules/mxgraph/javascript/mxClient.mi ...

Redirecting files from the file system to the emulator is not functioning properly

I am new to Phonegap and need help resolving this issue. In my application, I need to redirect to the List.html file when a button is clicked. Here is the code I have written: button1 function test() { window.location="/home/swift-03/phonegapexa ...

Ways to retrieve information and functions from defineExpose in Vue

`I am attempting to call a method from a child component within the parent component in Vue using the composition API. I have defined the method inside defineExpose, but I am unable to access it in the parent component. Hero.vue (ChildComponent) <templ ...