Numerous occurrences of Vue-Chartjs

My goal is to incorporate multiple Doughnut type graphs into a single component. Resource:

<div class="row">
    <div class="col-12 col-lg-6">
        <strong>All</strong>
        <Doughnut chart-id="workNonWorkData" :dataset-id-key="'key1'" :chart-data="workNonWorkData" />
    </div>
    <div class="col-12 col-lg-6">
        <strong>Approved</strong>
        <Doughnut chart-id="workNonWorkAprData" :dataset-id-key="'key2'" :chart-data="workNonWorkAprData" />
    </div>
</div>

Each doughnut operates individually when the other one is removed. However, when both are present, only the latter displays. I've verified that the canvas ids are unique. Could Vue be interpreting these as the same instance?

Answer №1

After switching from version 4.0.4 to 4.0.3, I found that it is now functioning properly.

I hope this information proves beneficial.

Answer №2

<script>
import { Bar } from "vue-chartjs";
import Chart from "chart.js";

var customPlugin = function(chart) {
    var width = chart.chart.width;
    var height = chart.chart.height;
    var ctx = chart.chart.ctx;
    ctx.restore();
    var fontSize = (height / 112).toFixed(2);
    ctx.font = fontSize 
    ctx.textBaseline = "middle";
    var text = 90;
    var textX = Math.round((width - ctx.measureText(text).width) / 4);
    var textY = height / 4;
    ctx.fillText(text, textX, textY);
    ctx.save();
}

export default {
  extends: Bar,

return {     
      options: {}
}

mounted(){
    this.addPlugin({
      id: 'custom-plugin',
      beforeDraw: customPlugin
    });
}

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

Instructions on how to make a radio button selected when clicked are as follows:

My radio button is currently checked, but I would like it to be onclicked because there is a Javascript function that uses the on.click function. Are there any possible methods or examples to achieve this? <label style="margin-left:177px;">Order Ty ...

Managing top scores for my game using a JSON data storage

I'm currently developing a game using Javascript and HTML5 canvas. Most of the work is done, but I'm facing an issue with implementing high score functionality. Since the game is simply an HTML page with various Javascript files (no database), m ...

Developing a customized autosuggest feature using AJAX with comprehensive keyboard accessibility

Has anyone tried building their own AJAX auto suggest text box with full keyboard support? I've managed to create the auto suggest feature by connecting to a SQL DB and displaying results, but the only way to interact with the search results is throu ...

What is the reason for elements such as "if" and "else" not being visually

I am currently developing a browser-based code editor with a unique feature. Task: The objective is to highlight specific keywords like if, else, for... when they are entered into the editor. textarea.addEventListener("input", function() { ...

Issue encountered while invoking the jQuery html method

Embarking on my first adventure with javascript + jQuery, creating a basic page but running into errors. I've gone through the code multiple times and still can't seem to find the issue. Below is the error message I am encountering: The complet ...

`How can I integrate jQuery UI using Webpack in my project?`

I recently initiated a fresh project utilizing React Slingshot and am experimenting with integrating jQuery UI accordions. I've included the jQuery UI plugin using NPM with the command npm install --save jquery-ui. From what I comprehend, Webpack auto ...

JavaScript - Toggle Checkbox State Based on Array Values

Currently, I'm in the process of building a Laravel user management system for a project. This system will allow admins to edit any selected user who is registered on our website. Upon clicking the edit button, a modal form containing the user's ...

javascript/jquery - steps to design an effective modal page overlay

Struggling for the past few weeks to create a modal dialog using javascript/jQuery. While iOS and Android devices seem to work fine, Windows mobile/Opera mobile often present issues with the modal size. It either requires excessive scrolling or ends up bei ...

Swap a jQuery class with another if the class for ul li is currently active

I am currently developing a form builder and I would like to customize the appearance, specifically changing the color of the text. I want the text to be white when the class is set to active, and black when the class is not active. Is there a way to achi ...

Dealing with Error TS2769 in Visual Studio Code when passing props to a custom component in Vue 2 with Typescript

I've encountered an issue with a Vue JS component that involves passing a custom prop. I am utilizing the Vue Options API without utilizing the class component syntax. Whenever I pass ANY prop to my custom component the-header, I receive an error sta ...

Using VueJS: How can I reference a variable by its string name instead of directly in a template?

Is there a way to access a variable defined in a <script> tag in a template using its string name? For example, in the code snippet below, I want to access the foo variable using table[0]: <template> <div> {{ table[0] }} {{ tab ...

How to send a value to a function in Angular from a different function?

Within my Angular Typescript file, I am working with two functions named data and lists. My goal is to pass the variable windows from the function data to the function lists. However, when attempting to call the function lists, I encounter an error: Canno ...

Using jQuery to select the next table cell vertically

Is there a way to utilize jQuery to access the cell (td) directly below a given cell in a traditional grid-layout HTML table (where each cell spans only one row and column)? I understand that the code below will assign nextCell to the cell immediately to ...

Incorporating Vuetify into a Vue CLI application with the help of webpack

I am facing an issue with my Vue CLI application that uses Webpack and Vuetify. The Vuetify components are not loading properly, and I keep getting the following warnings: Unknown custom element: < v-app > - did you register the component correctly? ...

Developing a dynamic table using data retrieved from an API within a JS React Bootstrap framework

I'm new to JavaScript and struggling with a problem. I am trying to create a dynamic table displaying information about cars using data from an API provided by a friend (full JSON shown at the end of the post). While I can successfully fetch and displ ...

What is the best way to add a bootstrap file to my ejs templates?

I recently installed bootstrap using npm with the command 'npm -bootstrap@3'. However, when attempting to include the bootstrap.min.css file from node_modules in my application, I encountered an error message on my console. Here is a screenshot o ...

Using curly brackets as function parameters

Can someone help me understand how to pass an emailID as a second parameter in curly braces as a function parameter and then access it in AccountMenuSidebar? I apologize for asking such a basic question, I am new to JavaScript and React. class Invoices ex ...

What is the best way to conceal a conditional panel in a Shiny app using JavaScript when any action or button is clicked that is not one of the designated inputs

I am looking for a way to hide the conditional panel shown below whenever there is any user input that is not related to clicking the "Delete" button or selecting an option from the selectInput() function in the conditional panel, as demonstrated in the im ...

Engaging with tasks like incorporating fresh elements into JavaScript code

I am looking to implement an event listener that triggers whenever a new element is added to the document or any of its children. Can someone recommend a method for accomplishing this? ...

Is it possible to eliminate a style that was applied using the .css() method?

Currently, I am using jQuery to modify the CSS and would like to know how to remove the styling that is being applied based on the input value provided: If the color is not '000000', then change the background-color of the body element to the sp ...