Tips for upgrading chart js in Vue application?

I am having an issue with updating a chart by clicking on a button. Although the data changes in the store, the UI does not reflect the update.

<div class="graph">               
  <button class="click" @click="changeUi">Update Chart</button>                
  <canvas id="mix" count="2"></canvas>
  <chartjs-line target="mix"></chartjs-line>
  <chartjs-bar :option="{legend: { display: false }}" 
  :labels="mylabels":datasets="mydatasets" target="mix"></chartjs-bar>
</div>
 export default {
 data(){
   return{
     mydatasets:[{   
       data: this.$store.state.data}], //I want to modify this data
       //data: [20, 50, 20, 41, 26, 15, 20, 10, 29, 5, 33, 55]
     methods:{
       changeUi(){
             this.$store.commit('changeChart')
             // I want to change it to this array [10, 30, 34, 23, 11, 15, 55, 30, 19, 35, 43, 21]
        }
    }
}

In main.js, I import the chart library like this:

  import 'chart.js'
  import 'hchs-vue-charts'
  Vue.use(window.VueCharts);

Answer №1

It is recommended to utilize store properties as a computed property within your components instead of placing them inside the data() method.

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

Understanding and aggregating data from JSON files

I am in possession of a group of json values outlined below {"labels":[ "time", "softirq", "user", "system", "nice", "iowait" ], "data":[ [ 1490088352, 0, 14.64646, 3.53535, 0, 1.0101 ], [ 1490088351, 0, 27.77778, 3.0303, 0, 0 ], [ 1490088350, 0.49751, 12 ...

Exploring the combination of v-for and v-if in Vue framework

I am in possession of an array of photos and I require, prior to the page loading, to change the SRC of the image. Here is an example: images: [ { name: 'Car', image: require('../assets/car.png') }, { name: 'Book', ima ...

When altering the object's state value in ReactJs, be cautious of the warning that states not to directly mutate the state. It is recommended to

Is there a proper way to change the status as an object? I attempted it in the following manner, but it seems incorrect as it generates a setState warning during compilation. I am seeking guidance on how to modify a state with an object value. class Anim ...

Custom hooks in Next.js do not have access to the localStorage object

I've encountered an issue with my custom useLocalStorage hook. It works perfectly fine with create-react-app, but when I try to use it with Next.js, the value in the initial state on line 3 returns undefined. Is there a way to bypass server-side rend ...

Send an Ajax request to the controller and retrieve a file to display in an iframe

I need to display the contents of a byte[] array in an Iframe and provide the option for the user to download the file in PDF format. My view has a button connected to an ajax call that sends the byte[] to my actionresult, which returns a FileContentResul ...

What are the steps to designing customizable drop-down content menus on websites?

I am looking to implement a feature where I can create content drop-down bars similar to the ones shown in the images. When a user clicks on the bar, the content should be displayed, and if clicked again, the drop-down should hide. I have searched for a so ...

Retrieve the most recent information from the API using axios and React hooks

I have access to an API that provides data, but I am only interested in the most recent information. The newest data is always located at the end of the dataset. For instance, if there are 50 points of data, the latest would be number 50. Can someone adv ...

Arrange array with objects in order of most recent date

I am in the process of developing a chat application where all contacts are stored as objects in one array: var contacts = [{name: "Ruud", age: 20},{name: "Elke", age: 17}]; Next, I have the chat messages for each contact saved in an array of objects: v ...

Is it possible to utilize axios in Vue while utilizing CORS in the API?

I am encountering an issue with making a GET request to a CORS enabled corona virus API using axios and Vue. I have no control over their server, and my Vue app was created with vue-cli. Interestingly, I am able to make two requests from different APIs - ...

Utilizing grease/tampermonkey (or any other browser extension) to filter out specific characters within webpage elements

Forgive me if my language is not accurate, as I am still learning about programming. The forum that I visit has cluttered the page with unnecessary and glitchy images and text for a promotion. This has made the forum difficult to navigate. I was successful ...

THREE.Raycaster delivering imprecise outcomes

I am currently working on creating a 2D scatterplot with tooltips, but I am facing an issue with the raycaster not detecting when a point is being hovered over. The tooltip seems to activate only when touching an object, which is correct behavior, but it d ...

The main attribute in the NPM package.json is missing or has no appropriate entry

I'm really struggling to figure out the best approach for setting up my package.json file. I have a JavaScript module that contains multiple reusable JS files, let's call it Module1. In Module1's package.json, the name attribute is set to " ...

Splitting an array into multiple arrays with distinct names: A step-by-step guide

I have a data set that looks like this: [A,1,0,1,0,1,B,1,0,0,1,A,1]. I want to divide this array into smaller arrays. Each division will occur at the positions where "A" or "B" is found in the original array. The new arrays should be named with the prefix ...

Navigating the missing "length" property when dealing with partial functions generated using lodash's partialRight

I've been utilizing MomentTimezone for time manipulation within the browser. My development stack includes TypeScript and Lodash. In my application, there is an accountTimezone variable set on the window object which stores the user's preferred ...

Ways to effectively shut down the jQuery context menu

I'm having trouble with a jQuery context menu that won't close when I want it to. Here are the functions I have set up: function openContextMenu(event) { event.preventDefault(); $("#custom-menu") .css({ top: eve ...

Tips for rendering only certain sections of a partial view?

Currently, I am in the process of developing a web application that utilizes jquery 1.9.1 and jquery mobile 1.3.2 within Visual Studio (MVC4 template). Throughout the application, there are numerous pages with a side panel feature. While the side panel con ...

Elevate your Material UI Avatar with an added level of

Attempting to give a MUI Avatar component some elevation or shadow according to the documentation provided here. <Avatar alt="Cindy Baker" src="/static/images/avatar/3.jpg" /> Enclosing the Avatar within a paper or Card element increases the size o ...

An error was encountered because it was unable to read properties of undefined, specifically in trying to access 'navigate'

Just diving into the world of react native and react navigation, I encountered this puzzling error. Uncaught TypeError: Cannot read properties of undefined (reading 'navigate') I'm scratching my head because I am using the exact same code ...

What is the best way to trigger a function when a chart changes in Nuxt using Vue JS?

How can I trigger a function whenever a chart is loaded or changed in Vue Nuxt JS? I've tried using created, mounted, updated, and beforeMount but none of them seem to work. Can anyone offer any guidance? Edit 1: Here's the code snippet: upd ...

Mysterious error arises in Internet Explorer versions 7 and 8: An expected colon is missing

One of our websites is encountering a puzzling JS error in Internet Explorer. The console displays the following message: ':' expected javascript:false, Line 1 Character 24 When attempting to trace the source of the error, a notification appear ...