By default, Vue chartjs does not enable datasets

For my clan project, Lords of War on the Supercell games, I am working on creating a chart to track current donations using chart.js. I am utilizing Vue for the front-end and vue-chartjs for the charts. However, I am facing an issue where the datasets are not visible when the page is initially opened. How can I resolve this problem?

Here is the chart data object:

donation_chart_data: {
     labels: [],
     datasets: [
         {
             label: 'Donated',
             hidden: false,
             backgroundColor: '#1D93D3',
             data: []
         },
         {
             label: 'Received',
             hidden: false,
             backgroundColor: '#C7031F',
             data: []
         }
     ]
}

This is the DonationChart component:

import { Bar, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins;

export default {
    extends: Bar,
    name: 'ClashRoyaleDonationChart',
    mixins: [reactiveProp],
    mounted () {
        // Overwriting base render method with actual data.
        this.renderChart(this.chartData,
        {
            responsive: true,
            maintainAspectRatio: false
        })
    }
}

PS: Interestingly, clicking the legend displays the data properly.

Answer №1

It seems like you're utilizing an API to retrieve your information, correct?

In order to ensure that the data is available before rendering your chart, it's important to keep in mind that Axios/Ajax requests are asynchronous. This means that your chart may display without any data most of the time.

To address this issue, simply add a v-if="loaded" directive to your chart component and within your axios.get().then() method, set loaded = true. By doing so, you should no longer encounter this problem.

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

What is the process of using a For loop to output a string in reverse order?

I'm attempting to reverse the string "hello" using a For loop, aiming for the output of "olleh". However, I'm facing an issue where the last character in the string is not being removed after being added to the array. Consequently, only the last ...

What is the best method for inserting content into a custom element as input for the component?

Currently, I am in the process of creating a syntax highlighting web component that will be able to highlight any content placed inside it. Let me illustrate with an example code snippet: <fs-highlight data-line-numbers="true" data-language=&q ...

Safeguard your Electron app's contents from theft

As I embark on creating an Electron app, my main concern is ensuring that the content - which consists of various mp3/png/svg files - remains exclusive to the app. It seems challenging to prevent users from accessing these files outside of the application, ...

Dividing and arranging dropdown list items into two columns using Bootstrap - An easy guide

How can I split a dropdown ul>li list into two columns using Bootstrap? I am attempting to divide the ul>li into two columns, with one aligning to the left and the other to the right. This is how I am currently doing it: <div class="btn-group" ...

Is it possible to receive real-time updates for a specific location in Cesium

I am currently developing a live tracking application using Cesium, and I'm encountering an issue with updating the point location on the map in real-time. Currently, my Cesium viewer successfully receives the data from the server in JSON format and ...

Why aren't jQuery change event handlers triggering on Bootstrap radio buttons?

My Bootstrap radio buttons are not triggering the jQuery change event handlers. How can I fix this issue? Please note that I specifically do not want to add event handlers to input or input[type=radio], but rather by using ID selectors. Here is a link to ...

Deciphering the JavaScript code excerpt

This information was sourced from (function ($, undefined) { // more code ... $.getJSON("https://api.github.com/orgs/twitter/members?callback=?", function (result) { var members = result.data; $(function () { $("#num- ...

Is there a way to conduct a Mongoose query that excludes or ignores specific strings?

I'm struggling to find a concise title, so please suggest ways to make it clearer. Now, onto my question - I need to query phone numbers in my database, but they are stored in two different formats: with dashes and without. For example: {phone: ' ...

Managing React state with custom objects

We are currently utilizing a react table component that requires selections to be maintained across different pages. To achieve this functionality, we have implemented a Map to store the selected rows and a custom class named Selections to manipulate these ...

Converting a 3D model from Unity to three.js for seamless integration

I am tasked with building a human body model in WebGL using three.js, but I only have a Unity model. Is there a way to export the Unity model as an object or something similar for this purpose? ...

Integrating AWS IVS quality plugin with video.js for enhanced video streaming in a Next JS application

Hello, I am new to AWS media services and recently started experimenting with AWS IVS for video streaming. I am currently working on integrating the AWS IVS quality plugin to Video.js. The player is up and running, displaying the video, but I encountered a ...

Can I access VueSession in main.js for Vue.js?

In my main.js file, I have set up the following configuration: import Vue from 'vue' import App from './App.vue' import VueRouter from 'vue-router' import Home from './views/Home.vue' import Login from './views/ ...

Tips for displaying "No Results" without causing any lag in the browser

I'm encountering difficulty trying to implement a simple feature without resorting to a "messy" solution. The performance is suffering, and I am certain it's not done in a "professional" manner. What I desire is straightforward – displaying a ...

What is the best method for enabling HTML tags when using the TinyMCE paste plugin?

After spending countless hours searching for a solution, I am still puzzled by this problem. My ultimate goal is to have two modes in my powerful TinyMCE editor: Allowing the pasting of HTML or Word/OpenOffice text with all styles and formatting attribu ...

Creating a personalized embed using data collected from user input with a prompt in Discord.js

I'm currently working on a feature that allows users to make suggestions using the command =suggest in the server. This command would trigger a prompt in their direct messages, asking for specific details. However, I am facing difficulties in capturi ...

What is the best way to link a close button to an open button with jQuery UI Dialog?

I am working on a project that involves creating a wizard-like experience using 5 jQuery Dialog modals. The idea is to have each modal open the next one in sequence while closing itself. However, I am facing an issue where all the modals remain open on top ...

The RangeError occurs when attempting to deploy to Heroku due to exceeding the maximum call stack size at Array.map in an anonymous function

While attempting to deploy a MERN stack application to Heroku, I encountered an error in the Heroku CLI. RangeError: /tmp/build_c861a30c/frontend/node_modules/@reduxjs/toolkit/dist/redux-toolkit.esm.js: Maximum call stack size exceeded at Array. ...

What is the best approach to add additional functionality to an already existing object method?

Let's say we have an obj, var obj = { l:function(){ alert(1); } } In what way can additional functionality be incorporated into obj.l without directly modifying the object? ...

Changing quotations to parentheses using Javascript Regular Expressions

Is there a way to utilize a regex in Javascript to replace the string sequence "*" with (*)? I'm looking to replace items between quotes with items enclosed in opening and closing parenthesis. For instance, transforming "apple" to (apple). Do you ha ...

What could be preventing my function from being invoked at regular intervals?

I have been attempting to trigger a function every few seconds with the following code snippet: HTML: <div id="Result">Click here for the message.</div> JS: $(document).ready(function () { $("#Result").click(function () { var ...