I'm having trouble getting the vue-chart.js to show up on the page

I'm currently in the process of learning how to utilize vue-chart.js and Chart.js. However, I've encountered an issue where the graph is not displaying on the main page.vue.

Below is the code snippet from ../src/Chart/RandomChart.vue:

<template>
    <div>               
        <random-chart></random-chart>
    </div>
</template>

<script>
import RandomChart from '../Chart/RandomChart.vue'
export default{
    components:{
        RandomChart
    }

}
</script>

Here is the code from ..src/Chart/LineChart.js:

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

export default {
  extends: Line,
  mixins: [reactiveProp],
  props: ['options'],
  mounted () {
    // this.chartData is created within the mixin.
    // If you want to pass options, create a local options object
    this.renderChart(this.chartData, this.options)
  }
}

And here is the code from RandomChart.vue, even though it's also documented in the official documentation:

<template>
  <div class="small">
    <line-chart :chart-data="datacollection"></line-chart>
    <button @click="fillData()">Randomize</button>
  </div>
</template>

<script>
  import LineChart from './LineChart.js'

  export default {
    components: {
      LineChart
    },
    data () {
      return {
        datacollection: null
      }
    },
    mounted () {
      this.fillData()
    },
    methods: {
      fillData () {
        this.datacollection = {
          labels: [this.getRandomInt(), this.getRandomInt()],
          datasets: [
            {
              label: 'Data One',
              backgroundColor: '#f87979',
              data: [this.getRandomInt(), this.getRandomInt()]
            }, {
              label: 'Data Two',
              backgroundColor: '#f87979',
              data: [this.getRandomInt(), this.getRandomInt()]
            }
          ]
        }
      },
      getRandomInt () {
        return Math.floor(Math.random() * (50 - 5 + 1)) + 5
      }
    }
  }
</script>

<style>
  .small {
    max-width: 600px;
    margin: 150px auto;
  }
</style>

Now, looking at the code from App.vue:

<template>
    <div class="app">
        <router-view></router-view>
    </div>
</template>

<script>
    export default{
        
    }
</script>
<style scoped>
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
</style>

Next, let's examine the main.js:

import { createApp } from 'vue'
import App from './App'
import router from "@/router/router";



const app = createApp(App)

app
    .use(router)
    .mount('#app');

Finally, here are the dependencies listed in the json file:

  "dependencies": {
    "chart.js": "^2.9.4",
    "core-js": "^3.6.5",
    "vue": "^3.0.0",
    "vue-chart-3": "^0.5.8",
    "vue-chartjs": "^3.5.1",
    "vue-router": "^4.0.11",
    "vuex": "^4.0.0-0"
  },

I have been troubleshooting for a while but can't seem to pinpoint the issue. It's possible that there's a minor mistake that I'm overlooking.

Answer №1

In order to use vue-chartjs with the latest version of chart.js (v3), you will need to either downgrade chart.js to version 2.9.4 or utilize chart.js without the vue wrapper:

npm uninstall chart.js
npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="385b50594a4c16524b780a1601160c">[email protected]</a>

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

Implement pagination for API calls within a React Component

I am trying to implement pagination for the results of an API call. The following code snippet shows how I am making the API call using Axios: apiCall() { const API = `http://www.omdbapi.com/`; axios.get(API, { params: { apikey: proces ...

Analyzing elements within an array of objects

Here is an array of objects I have: const cart = [ { group: "group 1", qtd: 12, value: 65, term: 20 }, //index 0 { group: "group 1", qtd: 10, value: 100, term: 20 }, //index 1 { group: "group 1", qtd: 18, value: 40, term ...

A guide to mastering pym.js

As a seasoned Java programmer, I find myself in unfamiliar territory with a project my boss assigned me. Following a discussion with an engineer from the client company, I'm tasked with creating a responsive iframe using pym.js. The issue? I have no p ...

Does Parsley.js offer a way to configure so that the parsley-success field is not added to an input if it should be completely ignored?

Currently, I am excluding one input and adding the success class (which is fine with me) $('form').parsley({ excluded: '[data-parsley-sum-total="all"]' }); However, there are several other inputs without any validations that I do not wa ...

What is the best way to incorporate animation into a React state?

Looking to implement a fade-in animation for the next index but struggling with tutorials using "react transition group" that are focused on class components or redux. https://i.sstatic.net/q791G.png const AboutTestimonials = () => { const [index, se ...

Utilize Javascript to input text into a webform

I am working on creating a bot that simulates user input for the WattsApp web website. When I manually type a message into the website, it enables a button that allows me to send the message. However, when my script runs, it finds the input box, changes t ...

Syntax Error Unearthed: Identifier Surprise Discovered in (Javascript, ASP.NET MVC, CSHTML)

I encountered an error when attempting to remove a dynamically created HTML element by clicking the corresponding remove button. The goal is to invoke the remove method at the end of the script and pass along certain arguments. However, I'm facing iss ...

Clicking on the mail icon will open the mail with the associated mail id

https://i.sstatic.net/6TLpN.pngWhen the mail icon is clicked, the mail will open with this email address. I am currently working on a project where clicking the mail icon will redirect to the mail signup page with the corresponding email address. In the ...

Tips for accessing a PDF file using AJAX

Is there a way to open a PDF file using AJAX? I tried the following code snippet: $.ajax({ type : 'GET', url : ApplicationParameters.getWebRoot() + 'E_Books/pdf/previews/' + jsonRecord[0].previewUrl, data ...

JavaScript conflicts will arise due to the introduction of Yammer Embed on September 30th, 2014

Is anyone else encountering problems with Yammer embed causing JavaScript errors today? Our various applications across different technologies (SharePoint, IBM, etc) have been functioning normally for months, but this morning we are suddenly seeing a sig ...

jQuery Counter Effect encountering isNaN error when trying to display a number retrieved from a get API object

I am looking to display the numerical data retrieved from an API using JSON. I want to incorporate a counter effect that displays "isNaN" if necessary. The API URL returns an object with the total number saved in data.data. Can anyone assist me with achi ...

"An issue has been encountered with lastID being undefined while using sqlite3 with Node

After successfully inserting into the database, I am encountering an issue where this.lastID is undefined. Can anyone help me troubleshoot this code? app.post('/products/create', (req,res) => { upload(req, res, (err) => { c ...

Usage of Google Charts within an Ajax partial in Rails 3.1

My experience working with Google charts has been smooth so far, but I've hit a roadblock where I need to display a chart inside an Ajax-rendered partial. Nothing is showing up, and I suspect it's because the JavaScript trigger to build the char ...

Is Vuejs utilizing a customized event directive that does not require an event handler?

The code snippet below shows how fireCheck captures clicks on the list items (<li>) and toggles the enclosed checkbox. There is a click listener on the checkbox that prevents event bubbling up to parent elements, ensuring that the enclosing <li&g ...

The Toggle Functionality necessitates a double-click action

I'm currently working on implementing a menu that appears when scrolling. The menu consists of two <li> elements and has toggle functionality. Everything is functioning properly, except for the fact that the toggle requires two taps to activate ...

Utilizing Material UI's (MUI) date picker in conjunction with react-hook-form offers a

I'm currently developing a form with a date field utilizing MUI and react-hook-form for validation. I have experimented with two different methods of rendering the field, but when I try to submit the form, the expected value is not being returned: Me ...

Fastify endpoint failing to respond to designated URL

Within my code, there is a router setup: fastify.get('/:link', (req, reply) => { req.params.url = req.host+req.url; reply.view("template.ejs",req.params); }); I am trying to capture URLs and process them in the template. All URLs are ...

Error message encountered when using Vue and typescript: "TypeError: Object prototype may only be an Object or null: undefined"

Encountered a TypeError: Object prototype may only be an Object or null: undefined I ran into an issue while working on my project. I'm utilizing vuejs, typescript, and jest. Despite having simple code, I encountered an error when trying to unit tes ...

How to send a JSON error message from PHP to jQuery

I am facing an issue where I want to display an error message if the username and password are incorrect. I have been trying to solve this since yesterday but I can't figure out what's wrong. Every time I receive an error and it displays the erro ...

assistance required (javascript and jquery timer function)

Whenever the button is clicked, a timer of 2 minutes starts. If the button is clicked once and the 2-minute timer completes before another click, everything works perfectly. However, if the user clicks the button before the 2 minutes are up, the timer rese ...