I seem to be experiencing some confusion with labeling in my pie chart and doughnut chart using Chart.js. Additionally, I am unable to properly display the charts themselves

Struggling to generate charts using vue js. The chart is displaying with crossed labels instead of the actual chart. I'm puzzled about what could be causing this issue.

https://i.sstatic.net/5hZXR.png

Supposedly, this should be a pie chart. However, the crossed labels are causing all the labeled data to be removed, resulting in an empty chart. Below is the code snippet.

export const productChartData = {

  type: 'pie',
  data: {
    labels: ['Purchased', 'Return', 'Cancelled', 'Shipped', 'Returned'],
    datasets:[
      {
        data: ['22, 33, 12, 18, 19'],
        backgroundColor: [
            'rgba(255, 99, 132, 0.2)',
            'rgba(54, 162, 235, 0.2)',
            'rgba(255, 206, 86, 0.2)',
            'rgba(75, 192, 192, 0.2)',
            'rgba(153, 102, 255, 0.2)'
        ],
        borderColor: [
            'rgba(255,99,132,1)',
            'rgba(54, 162, 235, 1)',
            'rgba(255, 206, 86, 1)',
            'rgba(75, 192, 192, 1)',
            'rgba(153, 102, 255, 1)'
        ],
        borderWidth: 1
      }
    ]
  },
  options:{
    maintainAspectRatio:false,
    title:{
      display:true,
      fontSize:18,
      text: "Products"
    }
  }

}

export default productChartData;

In my .vue file, I have the following method:

methods: {
      createChart(chartId, chartData){
        const canvas = document.getElementById(chartId);
        const ctx = canvas.getContext('2d');
        const myChart = new Chart(ctx, {
          type: chartData.type,
          data: chartData.data,
          options: chartData.options
        });
      }   
    }

Answer №1

Your chart rendering code is experiencing a problem:

data: ['22, 33, 12, 18, 19'] should actually be data: [22, 33, 12, 18, 19]. I made the necessary adjustments in the code pen and now it's functioning properly -> https://codepen.io/anon/pen/dwKjqM

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

Exploring Vue 3: Crafting a custom plugin using the composition API and enhancing it with Typescript type augmentation

Encountering an issue with displaying plugins properly within <script> and <template> tags on WebStorm. Firstly, let's take a look at my files and configuration: tsconfig.config.json { "extends": "@vue/tsconfig/tsconfig. ...

Tables inserted via ckeditor do not preserve the style attribute

After incorporating ckeditor into my web page along with the table plugin, I noticed that sometimes the width of tables created in the editor window extends beyond the boundaries of the webpage when displayed. To address this issue, I made some adjustments ...

Ways to retrieve the worldwide status across multiple Vue.js components

I am looking to create multiple characters in separate components. My question revolves around efficiently accessing a global variable without redundancy in code. I currently have an array containing 10 characters. index.js state: { ...

Display/Modify HTML form

Looking for advice on how to create an interactive HTML form that displays data and allows users to edit it by clicking 'Edit' before submitting changes. Any suggestions on how to implement this functionality? ...

Utilizing Multiple Checkboxes for Precision Search Refinement

Big thanks to Khalid Ali for the support provided up until now. I am currently working with an array of songs that each have descriptions, keywords, etc. I have a set of checkboxes that I want to use to refine a search. Essentially, if someone selects the ...

Verify whether the username is present in the Firebase database using JavaScript

Using Firebase Function, I have created a function that allows users to complete their profile by adding an entry to the Firebase Realtime Database. Here is an example of how the database structure looks: { users: { AeknQrtMIyPpC4EQDPNQYvQUxCA3: ...

How to load MTL files from local storage using Three.js in Chrome

I'm encountering an issue when attempting to load MTL files using Three.js on Chrome. While everything runs smoothly on Safari, I keep running into a cross-origin request error in Chrome when working with local files. I'm at a loss on how to reso ...

Converting rotation into a directional vector

I have a Three.js object and I am able to read its rotation. However, I am looking for a way to extract a vec3 that indicates the direction in which the object is currently rotated. Can someone provide guidance on how to achieve this? ...

Implementing modifications to all HTML elements simultaneously

In my HTML document, there are around 80 small boxes arranged in a grid layout. Each box contains unique text but follows the same structure with three values: name, email, and mobile number. I need to switch the positions of the email and mobile number v ...

Using jQuery to Extract HTML Content from a JSON Object

I'm completely lost on what I'm doing incorrectly, but the JSON string I have looks like this: jsonp443489({"content":"<!DOCTYPE html><html><head><title>Title</title></head><body><p>Hello World< ...

Get names with specific characteristics by using a Javascript object that acts as an associative array

Can someone help me with my code? I'm trying to create an input box that, when I type in "A", will display the names of students who have earned "A" grades. I feel like I'm close to getting it right, but there's something missing. Any assist ...

Adjust the child content within a React component based on the element's width, rather than the overall window size, by implementing dynamic resizing without fixed breakpoints

I am working with a react component that displays a div containing menu items which are aligned horizontally using inline-block. The menu items have text labels "Toy Store", "Configure your Toy", and "About Us". My challenge is to dynamically change the ...

Creating dropdown options within a DataGrid in Form.IO: A step-by-step guide

I'm currently working with the Form.IO JS library to develop a new form. Within this form, I need to include a DataGrid containing 11 components. To ensure all components fit inline, I have applied the CSS rule overflow: auto (overflow-x: auto; overfl ...

Load CSS stylesheet depending on Internet Explorer document mode

As I work on my website, I am facing the challenge of incorporating different versions of my style sheet based on the browser's document mode, not the browser mode. For instance, if the documentmode = ie8, I may need to load main_ie8.css, whereas for ...

Add an element to the jQuery collection before the last element, not at the end

My challenge lies in utilizing AJAX to post a comment. However, the last comment element features a submit button within it. Consequently, whenever a new item is appended, it appears after the submit button. <div class="commentContainer" > < ...

Exporting a Component with React can be done in two ways: named exports and

There's a common syntax I've come across in various files: import React, {Component} from react; While I grasp the concept of named exports and default exports individually, I'm uncertain about how React manages this when exporting its cod ...

Struggling with the Nivo slider not loading properly?

Check out my personal website. I'm having an issue with my Nivo slider not displaying properly - it just keeps loading. Any ideas on why this is happening and how I can fix it? Below is the CSS I am using: #slider { position:relative; width: ...

In the Swiper function of JavaScript within a Django template, the occurrence of duplicate elements (products) is being generated

Experimenting with displaying products in a Django template, I decided to utilize the Swiper js class. This allowed me to showcase the products within a div, complete with navigation buttons for scrolling horizontally. However, when testing this setup wit ...

The @azure/search-documents JavaScript SDK allows the SearchDocumentResult to retrieve facets

Is it normal for the facets property of SearchDocumentResult to only return undefined instead of the facets involved in the query and their values? If this is the expected behavior, is there an alternative method to access the facets using the sdk? ...

Tips on how to engage in a spontaneous audio experience

I am currently developing a Discord bot with the intention of having it play a random mp3 file upon joining a voice channel. case"join": message.delete( {timeout: 5000}) const voiceChannel = message.member.voice.channel ...