Padding for the doughnut chart in Chart.js canvas

My current setup includes a canvas featuring a doughnut chart created with chart.js enclosed in a div element that displays like this:

https://i.sstatic.net/yy1e4.png

The canvas has a red background to enhance visibility. Currently, the chart is centered within the canvas with additional padding on its sides. I am seeking a way to make the chart occupy the entire canvas without any padding so that the alignment of the canvas resembles that of the word "CPU" above it. Is there an option in chart.js that can achieve this?

Here is the HTML code:

<p class="header">CPU</p>
<div class="doughnut-canvas-container">
   <canvas id="doughnut-canvas" class="chartjs-render-monitor"></canvas>          
</div>

And here is the accompanying CSS code:

.header {
    color: white;
    font-size: 16px;
    font-weight: bold;
    font-family: Verdana;
    padding-left: 10px;
}

.doughnut-canvas-container {
    width: 30%;
}

#doughnut-canvas {
    background-color: red;
}

Answer №1

It's difficult to pinpoint the exact issue without reviewing your chart creation code.

Typically, when you remove the legend and title, the chart should expand to fill the canvas completely. Here is a sample code snippet showcasing this:

new Chart(
  document.getElementById('doughnut-canvas'),
  {
    type: 'doughnut',
    data: {
      datasets: [{
        data: [2, 1],
      }]
    },
    options: {
      legend: {
        display: false
      },
      title: {
        display: false
      }
    }
  }
);
body {
  background-color: #000;
}
.header {
  color: white;
  font-size: 16px;
  font-weight: bold;
  font-family: Verdana;
  padding-left: 10px;
}

.doughnut-canvas-container {
  width: 30%;
}

#doughnut-canvas {
  background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<p class="header">CPU</p>
<div class="doughnut-canvas-container">
  <canvas id="doughnut-canvas" class="chartjs-render-monitor"></canvas>
</div>

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

Troubleshooting: Unable to Open Page with Google Material Button in Angular 5

Currently, I'm facing an issue with a button that is not opening to a new site despite following what seems like simple steps. <button mat-raised-button href="https://www.google.com/" color="primary">Connect with Stripe</button> I even a ...

Experiencing an issue while rendering due to the presence of display: table-cell;

I am currently in the process of developing a website. The HTML Header section is structured as follows: <div id="page"> <header> <a href="#" class="redsquare">&nbsp;</a> <div class="head-wrapper"> ...

Enhancing NG Style in Angular 6 using a custom function

Today, my curiosity lies in the NG Style with Angular 6. Specifically, I am seeking guidance on how to dynamically update [ngStyle] when utilizing a function to determine the value. To better illustrate my query, let me present a simplified scenario: I ha ...

What is the best way to stretch my background image to cover the entire screen?

I am working on a Python Django project and I want to create a full-screen background. The HTML code: { % load static %} <!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags--> <meta charset=" ...

Personalizing Material-UI's select component: A step-by-step guide

Desired Outcome: https://i.stack.imgur.com/khNHn.png https://i.stack.imgur.com/dQzVz.png Progress So Far: https://i.stack.imgur.com/CUixn.png Struggling to Position SVG Icon Next to Text: https://i.stack.imgur.com/4GFtA.png Issue with Black Line Whe ...

How to display a div in Angular when hovering with ElementRef and Query List

I am having trouble implementing a ngFor loop in my project where I want to display a div on mouse hover using the @Input notation. This is how my HTML code looks: <div class="col s12 m6" style="position: relative" *ngFor="let res of hostInfo.resident ...

Modifying CSS stylesheet does not alter the background color

body { background-color: bisque; } <!DOCTYPE html> <html> <head> <title>Reading</title> </head> <body> <h1> <button><a href="index.html">Home</a></button> & ...

Is now the ideal moment to implement Angular 4?

When considering using Angular 4 for an enterprise SAP system, is it better to stick with Angular 2 and wait for the final release of Angular 4? There have been rapid releases of Angular 4 that may affect our decision. (View changelog) Your suggestions ar ...

Integrate a scrollbar seamlessly while maintaining the website's responsiveness

I encountered an issue where I couldn't add a scrollbar while maintaining a responsive page layout. In order to include a scrollbar in my datatables, I found the code snippet: "scrollY": "200px" However, this code sets the table size to 200 pixels r ...

Updating webdriver-manager can sometimes result in a "spawn Unknown system error -86" message. This error

(Angular). webdriver-manager 12.1.7 is causing issues specifically on Intel-based Macs. When running e2e tests, the error message "spawn Unknown system error -86" is encountered. The bug has been addressed in webdriver-manager 12.1.8, however, I am facing ...

Tips for ensuring elements in a button are not vertically centered

My dilemma is unique: while many struggle with vertically aligning elements, I face the opposite issue. The contents of my button are currently vertically aligned, but I want them to wrap around like a normal <div> while retaining its clickable funct ...

How to align a div with embedded tweets in the center

I am looking to include a series of tweets from Twitter in a div on a basic webpage. The challenge is centering this div horizontally on the page. I have tried using: <div style="text-align:center"> and also: <div style="width: 900px; display ...

implementing a directive in an Angular 2 component

Just finished putting together a basic project with angular 2. Ran into an issue when attempting to include a directive component in the app.component - getting a red underline under the 'directives' property. Anyone out there know what's go ...

Angular to ExpressJS Backend Communication Leads to Unexpected Body Formatting Issues

For the purpose of learning Angular as a frontend and using Express as the backend, I am working on a simple todo list application. The database is managed with Sequelize. When attempting to add a user by posting to the node backend, the resulting object f ...

The background of the ACTK Modal Popup vanishes after multiple instances of scrolling up and down

The issue I'm facing is with the AJAX Control ToolKit Modal Popup's background (the blind curtain) disappearing after scrolling up and down several times. I have attempted to resolve this by applying various CSS styles, but unfortunately, none of ...

Implement a method to iterate through documents received from an express router in order to generate data for plotting charts using chart.js

I am currently diving into the world of node js (express js) and embarking on a journey to create a chart using data fetched from mongo db through mongoose. My goal is to iterate over the documents retrieved from the database in order to utilize them for p ...

Server-Side Rendering (SSR) is failing to generate any HTML output

I recently integrated Angular Universal SSR into my Angular application. Everything is working perfectly fine locally without any errors during the yarn build:ssr or yarn dev:ssr commands. Upon starting the server and inspecting the source, I can see all t ...

Custom-designed background featuring unique styles

I have implemented the following code to create a continuous running banner: <style> #myimage { position: fixed; left: 0%; width: 100%; bottom: 0%; background:url("http://static.giga.de/wp-content/uploads/2014/08/tastatur-bild ...

Retrieving the ng-content from an ng-template within one component and passing it to another component

Although there are various approaches available, my preference is to utilize ng-template, ng-content, and the @ContentChild() decorator in a specific way inspired by the implementation of Angular Material components. In this scenario, I have defined two c ...

Testing Angular 2: Ensuring Component Properly Calls Router with Accurate Arguments

I'm facing an issue with a child component that includes a button element with 'routerlink' attribute for navigation upon clicking. The button does not have a '(click)' handler, only the routerlink. Currently, I am writing a unit ...