Modify the property of an element during execution

I am tasked with developing a button that can change the type of a chart component (e.g., from columns to pie) upon clicking. However, I am unsure how to implement this functionality within the component structure. The goal is to modify the :series-defaults-type property when the ChangeType button is clicked.

<template>
    <div style="width: 100%;overflow: overlay;border-radius: 20px;">
        <button id="changeType" @click="changeType()">Change</button>
        <chart-more-option :kpiName="'EquipmentRetirementForecast'" v-if="showMoreOptions"/>
       <chart :title-text="'Equipment Retirement Forecast'"
              :title-color="'#FFF'"
              :title-font="'openSans'"
              :chart-area-background="'#1B1534'"
              :legend-visible="false"
              :series-defaults-type= "'column'"
              :series="series"
              :category-axis="categoryAxis"
              :axis-defaults-color="'#FFF'"
              :axis-defaults-labels-rotation-angle="'30'"
              :value-axis="valueAxis"
              :tooltip="tooltip"
              :theme="'sass'"
              :zoomable-mousewheel="true">
        </chart>
    </div>
</template>

<script>
import { Chart } from '@progress/kendo-charts-vue-wrapper';
import ChartMoreOption from '../ChartMoreOption';

export default {
    name: 'EquipmentRetirementForecast',
    components: {
        'chart': Chart,
        ChartMoreOption
        
    },
    props:  {
        fetchData: {
            type: Boolean,
            default: false
        },
        showMoreOptions: {
            type: Boolean,
            default: true,
        },
    },
    watch: {
      labelAlign(){
        var c = this.$refs.chart
        c.updateWidget();
      }
    },
    computed:{
        requestBody(){
            return this.$store.getters['usersession/getTopologyRequestBody']
        },
        series(){            
            return this.$store.getters['riskmanagement/getRetirementForecastSeries']
        },
        categoryAxis(){            
            return this.$store.getters['riskmanagement/getRetirementForecastCategoryAxis']
        },
    },
    data: function() {
        return {
            valueAxis: [{
                line: {
                    visible: false
                },
                minorGridLines: {
                    visible: true
                },
                labels: {
                    rotation: "auto"
                }
            }],

            tooltip: {
                visible: true,
                template: "#= series.name #: #= value #",
            },

        }
    },
    mounted(){   
        if(this.fetchData){     
            this.$store.dispatch("riskmanagement/FetchRetirementForecastData",this.requestBody).then(()=>{

            });
        }
    },
    methods: {
        changeType(){
            //implementation pending
        }
    }
}
</script>
<style src="../style-dashboard.scss" lang="scss" scoped />

This is the specific chart requiring modification:

https://i.sstatic.net/2tQvV.png

While changing the :series-defaults-type manually to pie produces the desired outcome, I aim to automate this change via a button click as depicted below:

https://i.sstatic.net/gQjjU.png

Answer №1

Include a new property called data with the default value of 'column', and name it something like chartType. Then, within the changeType() function, assign this.chartType = 'pie'. Finally, update

:series-defaults-type= "'column'"
to
:series-defaults-type= "chartType"
.

Additionally, avoid using : for hardcoded attribute values. For instance, change

:chart-area-background="'#1B1534'"
to
chart-area-background="#1B1534"
.

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 best way to retrieve JSON data using JavaScript within a loop?

I'm struggling to retrieve data from a JSON object. Here's the JSON structure I'm working with: var data = [ {"mes":{ "January":{ "Inversion":"1000","Fans":"1020"} ...

Using Vue.js's ref within a v-for iteration

When attempting to utilize components within a v-for loop and initialize the ref for future access to their methods from the parent component, I encountered an issue. Below is a simplified version of the code that demonstrates my scenario: <template> ...

How to implement and utilize a history-object interface in React with Typescript?

Can you help me with setting up an interface for a history object in my component? Currently, it is typed as any and I want to type it appropriately. Object: Here's the code snippet: import React, { useState } from 'react'; import { Row, C ...

Issue with tensorflow.js multiple regression stochastic gradient descent optimization

Greetings, everyone! I have recently encountered a perplexing issue while attempting to fit a curve in tensorflow.js. Despite spending a considerable amount of time on it over the past couple of days, I haven't been able to resolve it yet. Given that ...

Exploring hierarchical information within a JSON response from a Wiki API

As a newcomer to this field, I am currently exploring ways to access Wikipedia's API for extracting the value of "extract" and adding it to an HTML element dynamically. The challenge lies in the fact that the information is subject to change based on ...

React Three Fiber - THREE.BufferGeometry.computeBoundingSphere(): The calculated radius is invalid. It is possible that the "position" attribute contains NaN values causing this issue

Currently, I am working on a website using Reactjs and React Three Fiber for 3D components. Out of the total 3 3D components, 2 are functioning properly. However, one of them suddenly stopped working more than 6 hours ago, and I have been unable to find a ...

How to make a GET request to a Node server using Angular

I am currently running a node server on port 8000 app.get('/historical/:days' ,(req,res,next){..}) My question is how to send a request from an Angular app (running on port 4200) in the browser to this node server. Below is my attempt: makeReq ...

Is there a way to incorporate the Indian rupee symbol into a Google chart?

I've been trying to incorporate the Indian Rupee symbol into a Google chart using the code below: var formatter = new google.visualization.NumberFormat({ prefix: '&#8377;' }); However, I'm encountering an issue where ...

The changes to the grid options do not reflect immediately on the UI Grid interface

I am currently working on a project using the UI Grid module in AngularJS. I want to include row filtering as an option, but since not all users require it and the filter boxes take up a lot of space, I decided to disable filtering by default and add a but ...

Instructions on converting Dart to JavaScript for a non-web platform

I am interested in compiling Dart to JS for a non-web target, such as fermyon/js or node How can I compile Dart to JS for a non-web target? Update: I have been informed that it is possible, and although I couldn't find specific documentation, there ...

Struggling to convert a JSON file into a TableView within a JavaScript application developed with Appcelerator

Trying to display a JSON file in a table using JavaScript and Appcelerator is proving to be quite a challenge. The output appears as an empty table when compiled to an example page. As someone relatively new to JavaScript and JSON, I'm seeking guidanc ...

There was an issue with the Discord.js (v12) Giveaway Command that resulted in an error stating "Error: Cannot read property 'hasPermission' of undefined"

Hey everyone, I'm trying to develop my own Discord bot and I want to add a giveaway command to it. I found an example code online that I tried to implement, but unfortunately, it's not working as expected... const ms = require('ms'); c ...

What steps do I need to follow to integrate Vue.js into my Laravel Project?

I am familiar with Laravel and I have been attempting to incorporate Vue.js into my projects, but I am encountering some difficulties. Initially, I made sure to install Node.js and npm. Now, I am trying to use the command 'npm run watch' to chec ...

The hyperlink element has been added but is not clickable

I'm attempting to incorporate a download feature into my webpage using Greasemonkey. Despite successfully adding the new div element to the page, I am encountering an issue where the download window does not open as expected. var iDiv = document.crea ...

The Fancybox iFrame is not appearing on the screen

I am facing an issue with the html and javascript code I have. The html looks like this: <ul> <a class="iframe" href="/posting/form?id=8"><li>Publish</li></a> </ul> and I am using the following javascript: <scr ...

Javascript redirection not functioning correctly

Currently, I am working with PHP Codeigniter. The current URL of my page is => http://localhost.hbs.com/hbs/merchant/login I want to redirect my page to => http://localhost.hbs.com/hbs/category when a specific event occurs. I have attempted to achie ...

What is the reason for XMLHttpRequest overwriting preexisting events?

After clicking a button, I trigger an XMLHttpRequest event. However, I noticed that the original event becomes null once the request is sent. Why does this occur? Is there a way to maintain the original event? document.getElementById('start') ...

Retrieve data from MongoDB using the find() method results in an empty response, however,

While working on a project to practice my MongoDB skills, I encountered an issue with retrieving all the data from MongoDB. Despite receiving a successful 200 response, I was unable to properly extract all the data. Using Express framework for this task, ...

What could be causing my initial Vue component not to compile? / Steps for loading the vue-formio module

As a newcomer to both Vue and Form.io, I seem to be missing something simple here. The error message "Module not found: Error: Can't resolve 'vue-formio'" keeps popping up in my Form.vue component: <template> <formio src="https:/ ...

The deployed vue.js application encounters a 404 error when the page is refreshed within the vue-router

While the homepage/base URL of the app can be refreshed with no problem, other pages return a 404 error when refreshed. Are there any workarounds for this issue? Take a look at this screenshot of the 404 error: [1]: ...