Vue Doughnut Chart with curved and evenly spaced sections using Chart.js (vue3-chart-v2)

Is there a way to create rounded arcs with spacings in a Chart.js Doughnut Chart similar to the example shown here?

https://i.sstatic.net/66A2Z.png

I have attempted to achieve this by adjusting the "borderRadius" and "offset" properties in the Dataset Properties as well as the arc spacing, but so far it hasn't worked.

I am using 'vue3-chart-v2' in my Vue 3 App.

Here is my code:

import { defineComponent } from ‘vue’;
import { Doughnut } from ‘vue3-chart-v2’;
export default defineComponent({
name: ‘PieChart’,
extends: Doughnut,
props: {
    carbonData: Object
},
data() {
    return {
         chartData: {
             labels: [‘A’, ‘B’, ‘C’, ‘D’],
             datasets: [
                  {
                  data: [ this.carbonData.slabs, this.carbonData.columns, 
                  this.carbonData.foundation, this.carbonData.core ],
                  backgroundColor: [‘rgba(143, 188, 143, 0.7)’, ‘rgba(135, 206, 250, 0.7)’, ‘rgba(205, 133,63, 0.7)’, ‘rgba(230, 78, 62, 0.7)’],
                  offset: 1,
                  weight: 1,
                  borderWidth: 1,
                  borderRadius: 15
                  }
            ]
        },
        options: {
        elements: {
            arc: {
                 spacing: 15
            }
        },
        cutoutPercentage: 70,
        responsive: true,
        maintainAspectRatio: false,
        legend: {
             position: ‘right’,
        }
     }
}
},
mounted () {
    this.renderPieChart();
},
methods: {
    renderPieChart() {
        this.renderChart(this.chartData, this.options);
    }
},
})

Answer №1

It seems that the issue may be related to using chart.js V3.0.0. In this version, the borderRadius for arcs was introduced and there were spacing issues up until V3.4.0. To resolve this, make sure you are using chart.js V3.4.0 or later:

var options = {
  type: 'doughnut',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    }]
  },
  options: {
    cutout: '90%',
    radius: '90%',
    plugins: {
      legend: {
        display: false
      }
    },
    elements: {
      arc: {
        spacing: 50,
        borderRadius: 15
      }
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.4.0/chart.js"></script>
</body>

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

Collaborating on a basic JavaScript/jQuery user interface component

Having limited experience with jQuery and JavaScript, I am now tasked with adding a slider to an .ASCX page. Here is part of the code snippet from that .ascx file: <tr> <td style="width: 140px; height: 25px;"><asp:Label ID="lblHeader" r ...

Showing No Data Available in Angular 2

Is there a directive in Angular 2 that can help display "No data found" in a table when it's empty? Alternatively, can I create this functionality in my services when subscribing to fetched data? <table> <tbody> <tr *ngFo ...

Identifying text within clicked divs using identical ids

$(document).ready(function(){ $('#peoplelayer').click(function(){ $(this).fadeOut(500); var str = $(this).text(); alert(str); }); }); This is code where I use the same id "#peoplelayer" for all the divs. When on ...

Is there a way to utilize namespace import without bringing in all the other imports as well

Within our angular application built with typescript, we make use of lodash. Our current approach to importing lodash is demonstrated below: import * as _ from 'lodash'; //.. code which utilizes _.pluck() However, in order to optimize for tree ...

Include @url.action with a parameter on a cell within a table using AJAX

I am new to this and I want to add an action method on a table cell. The challenge is that the table is generated using JavaScript (AJAX). Here's the code: $.ajax({ url: "GetData", contentType: "application/json; charset=utf-8 ...

Strategies for avoiding text selection interference with onMouseMove event

I am in the process of adding a "resize handle" to adjust the width of my left navigation panel. This handle, represented by a div, triggers an onMouseDown() event that calculates the necessary widths and applies them to the relevant elements during subseq ...

What is causing the inability to successfully copy and paste Vega editor specs locally?

I successfully executed this spec in Vega Editor: { "$schema": "https://vega.github.io/schema/vega/v3.0.json", "width": 1, "height": 1, "padding": "auto", "data": [ { "name": "source", "values": [ {"name": "Moyenne","vo ...

Is there a way for multiple <select> elements to have identical options in React?

Currently, I have a React component structured like this: export default function ExampleComponent() { return ( <div> <select required name="select1"> <option label=" "></opti ...

Using Intersection Observer in Typescript causes a bug when utilized with useRef

Currently, I have a text animation that is functioning flawlessly. However, my goal now is to implement an Intersection Observer so that the animation only triggers when I scroll down to the designated box. To achieve this, I utilized the useRef React hoo ...

Ways to update a value in a table by comparing two JSON objects

I am currently working with two JSON files containing data as shown below: JSON 1: let classes = [{ "Class": "A", "as_of": "12/31/2020", "student": [{ "raji": { "eng": ...

Using Jquery to dynamically load an aspx page into a specific div element

Yesterday, I posted a question about loading an aspx page in a div tag. I have been using the code below to try and accomplish this, but so far I have been unsuccessful. Can anyone provide assistance on how to successfully load the aspx page into the div ...

Error when accessing JSON property in Angular with Ionic 2: A Strange TypeError

I have implemented a provider in my Ionic project to fetch the user object from storage. Below is the code: import { Injectable } from '@angular/core'; import { Storage } from '@ionic/storage'; @Injectable() export class ApiProvider { ...

Expanding and collapsing UI elements within an ngRepeat loop in AngularJS

I have been attempting to incorporate collapsible panels within an ngRepeat loop. Below is the code I have been using: <div class="panel panel-default" ng-repeat="element in elements"> <div class="panel-heading"> ...

When trying to assign the result of res.send() to another variable in NodeJS Express, it does

My current Express version is 3.4.4 and I encountered an issue when trying to implement the following code: var cb = res.send; cb(result); This resulted in an error message: ...\node_modules\express\lib\response.js:84 var HEAD ...

Creating JavaScript classes based on JSON schemas

I have a JSON file containing information and data related to my work, presented in the following format: { "Employees":[ { "id": 1, "fullName": "Test Test" } ], "Infos":[ { "id": 1, ...

Identify moving objects with react-beautiful-dnd

I've successfully implemented a draggable list using react-beautiful-dnd by following the tutorial. The result looked like this: https://i.sstatic.net/loXA2.png You can find the code for this implementation here: https://github.com/DDavis1025/react- ...

Error in hook order occurs when rendering various components

A discrepancy was encountered in React when attempting to render different components Warning: React has detected a change in the order of Hooks called by GenericDialog. This can result in bugs and errors if left unresolved. Previous render Next ren ...

What is the best way to display a selected checkbox in an AJAX editing modal?

Can someone assist me in loading the checked checkboxes in an edit modal? I am using checkboxes to assign multiple roles in my system. Everything was working fine, but I encountered an issue with my edit modal where the checkboxes appear blank and unchecke ...

What is an alternative method for creating a horizontal line without the need for the <hr> tag?

Is there a way to create a slim horizontal line without using the <hr> tag ? This is what I attempted: .horizontal-line{ border-top: 1px solid #9E9E9E; border-bottom: 1px solid #9E9E9E; } While it does function, I am hoping for a thinner line. ...

Exploring the Power of Angular 5 with TypeScript and ES2015 Syntax

I have been working on an angular 5 application where I needed to incorporate the dmn-js library. Unfortunately, this library does not come with typings available. To tackle this issue, I followed the guidelines provided in the Angular-CLI wiki regarding h ...