creation of pie chart embedded within a donut chart utilizing the functionalities of chart js

For my project, I have been utilizing chart js to create visually appealing charts. Currently, I am faced with the task of drawing a pie chart within a donut chart similar to this example: https://i.sstatic.net/AO0os.png

The data in the donut chart is not dependent on the data within the pie chart that it contains. Additionally, color selection is not crucial for this particular visualization. Does anyone have any innovative ideas on how to achieve this?

As of now, I can only generate the pie chart and the donut chart separately.

function drawOperatorStatusChart(labels, data, title, colors) {

new Chart(document.getElementById("pie_chart_operator"), {
    type: 'pie',
    data: {
        labels: labels,
        datasets: [{
            label: data,
            backgroundColor: colors,
            data: data
        }]
    },
    options: {
        tooltips: {
            callbacks: {
                label: function (tooltipItem, data) {
                    return secondsToHHMMSS(data['datasets'][0]['data'][tooltipItem['index']]);
                }
            }
        },
        title: {
            display: true,
            text: title
        }
    }
});
}

function drawReportDetailedDoughnutChart(labels, data, title, colors) {

var ctx = document.getElementById('operator_detailed_doughnut_chart').getContext('2d');

new Chart(ctx, {
    type: 'doughnut',
    data: {
        labels: labels,
        datasets: [{
            label: "",
            backgroundColor: colors,
            data: data
        }]
    },
    options: {
        responsive: true,
        legend: {
            position: 'top',
        },
        title: {
            display: true,
            text: title
        },
        animation: {
            animateScale: true,
            animateRotate: true
        }
    }
});
}

Answer №1

One approach worth trying is using the position absolute property.

Check out a demonstration of my suggestion here: http://jsfiddle.net/mw74n8be/

<canvas class="fixed" id="standChart"></canvas>

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

Leveraging async/await in express

I am encountering an issue with my app.post method while trying to deploy on Firebase. The error message reads: Parsing error: Unexpected token =>. I am fairly new to node.js and Javascript as I primarily work with Swift. However, I require this code fo ...

Troubleshooting the ckeditor-duplicated-modules error when trying to install a local npm package that should utilize the node_modules of the main project through yarn

As I work on my MainProject, I'm attempting to set up a local version of the ckeditor-5 plugin PeteCkPlugin that was generated using the ckeditor5 package generator. I experimented with using yarn link within the local directory of PeteCkPlugin, foll ...

There was an error in the code: Unexpected token M

Is there a solution for this error that anyone can share? The Google Developer Tools are not able to identify the exact location of the problematic code, making troubleshooting difficult. I am using Meteor and MongoDB. I have looked into Unexpected toke ...

Struggling to display AJAX GET results on my webpage, although they are visible in the Google Element Inspector

I'm working on a basic invoice page where I need to populate a dropdown box from my MySQL database. The issue I'm facing is that when I select an item, the description box doesn't get prepopulated as expected. I've checked in the networ ...

Is there a way to verify within the "if" statement without repeating the code?

Is there a way in javascript (or typescript) to prevent redundant object rewriting within an if statement condition? For example: if (A != null || A != B) { // do something here } // can it be done like this: if (A != null || != B) { // avoid repeating ...

Vue warning: Do not modify the prop "taskToEdit" directly

I am facing an issue with my props editToTask : app.js:42491 [Vue warn]: To prevent overwriting the value when the parent component re-renders, avoid directly mutating a prop. Instead, use a data or computed property based on the prop's value. Mutate ...

Gathering feedback from a webpage using JavaScript and jQuery

I have been experimenting with different tools such as Selenium and BeautifulSoup in an attempt to scrape the contents of the following website/pages: . Specifically, I am looking to extract the reviews/sections which are dynamically loaded by JS, jQuery ...

The issue of height and width always being zero in Chrome when using Classic ASP with JavaScript

Within my markup, I have an image field that I am setting the source for using JavaScript. I am in need of its height and width, so I utilized the image.height() and image.width() methods. Despite working properly in Internet Explorer, these methods do not ...

Does Javascript move beyond the for loop and then return to it?

Currently, I am working on creating a stopwatch in JavaScript that counts by milliseconds using setTimeout. However, I encountered an issue during the initial setup: var time = 0; function main() { for (var i = 0; i < 5; i++) { setTimeou ...

Preserving state values with the useState hook throughout various function invocations

When I click the button to delete department rows from my table, I am using the "deleteDepartment" function. The issue arises when trying to get the selected row index in the "selectedRows" hook. It seems that the "rowSelection" state keeps accumulating va ...

What is the functionality of Google Chrome's "New Tab" iframes?

Have you ever wondered about those 8 small iframes displaying your most visited websites? How do they capture snapshots of the websites? How are the websites chosen for display? And most importantly, how do they actually work? Edit: I want to learn how to ...

Guide to successfully integrate MathJax into your React application

I developed an application using HTML that successfully rendered MathJax equations through a script tag. However, after transitioning to React, the MathJax equations are no longer appearing. I have tried adding the MathJax script (shown below) in the comp ...

The functionality of scrolling in Windows is not functioning properly in Selenium WebDriver

I am facing an issue where I need to click on an element that is being intercepted by another element. My workaround involves scrolling down the vertical scrollbar in order to reach my target element. To achieve this, I am using the following code snippet: ...

Icon: When clicked, initiate a search action

I am looking to make the icon clickable so that it can be used as an alternative to pressing the "return key" for searching. Check out this bootply example at . You simply need to click on the magnifying glass icon and it will initiate the search. ...

Display elements in an array of objects when the value changes with React

In my code, I am working with a nested list where each element has child nodes including id, name, and ancestors. The ancestors node contains an array of names and ids of the parent node, grandparent node, and so on. Here is an example: { "name": "Chi ...

Launching an Angular application from the local server

I have successfully deployed an Angular frontend on a server. It is functioning well, with three scripts: /runtime.0fad6a04e0afb2fa.js /polyfills.24f3ec2108a8e0ab.js /main.a9b28b9970fe807a.js My goal is to start this application in Firefox without ...

Learn the steps to extract attributes from a jQuery-selected element effortlessly

for instance <a href="http://stackoverflow.com" class="selected">stackoverflow</a> this is my jquery code snippet alert($('.selected').attr('href')); however, it's not functioning Can anyone provide guidance on how ...

Changing an item in a refined list

Here is an array written in Typescript: [ { "size": "100.34 KB", "name": "Phone.jpg", "documentoContentType": "image/jpeg", "type": "object" }, { "size": "606.34 KB", "name": "Tulips.jpg", "documentoContentType": "image/jpeg", "type": "flower" }, ...

When the Ajax done callback is not a function, it does not wait as expected

The Opening Act: After spending a few months working with traditional Ajax calls, a small error in my code today made me realize that there's still so much more to learn in this area. I find myself in need of some clarity on the matter. The Incident ...

Retrieving data from a database using a Symfony2 controller in JavaScript

I have been trying to retrieve a list of categories from my database and store it in my JavaScript code for future use. However, I have run into issues with this task as the list appears empty after being returned to JavaScript. Below is the code for my S ...