swap out a single amchart for a different one

Here's the current amchart I have:

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

I'm looking to create another amchart with the same data. Essentially, I want to replace the existing graph.

You can find the new chart here ->

This is my Angular code:

prepareDataForTemplate(res) {
    // Your code logic goes here...
}

loadChart() {
    // Your code logic goes here...
}

The method loadChart() is where I need to update the graph...

In the amchart documentation ->

I'm having trouble understanding how to integrate the amchart code with my loadchart() method?

Apologies for all the questions!

Answer №1

Although I'm still learning about amcharts, I'll attempt to provide some guidance.

Initially, it is assumed that you can save a reference to the chart you wish to replace. This reference could be defined as follows:

  private chart: am4charts.XYChart;

When creating your chart for the first time, you can follow this approach:

this.chart = am4core.createFromConfig(this.lineChartReturn, 'htmlIdReference', am4charts.XYChart);

If your implementation resembles the above structure, you can simply utilize the dispose function to remove the existing chart and then recreate it with the new data from lineChartReturn generated in the loadChart method.

loadChart() {
    if (this.chart) {
        this.chart.dispose();
    }

    // Your current logic to generate the new this.lineChartReturn

    // Re-create the chart using createFromConfig
    this.chart = am4core.createFromConfig(this.lineChartReturn, 'htmlIdReference', am4charts.XYChart);
}

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

Error message: 'React TypeScript: (props: OwnProps) => Element' cannot be assigned to type 'FunctionComponent<{}>'

Everything seems to be working fine as a JSX element... interface OwnProps { children: JSX.Element; location: Location; } export function Layout(props: OwnProps): JSX.Element { However, when I convert it into a functional component, an error occurs ...

Is it possible to implement jQuery events on all elements belonging to a specific class

Hey there, I'm facing a little challenge with my code. Currently, I have a snippet that allows a user using iOS to drag around a <div> with the class .drag on the webpage. Everything works perfectly when there's only one instance of .drag, ...

Guide to accessing HTML elements and saving them in a JSON formatted text using JavaScript

If you have an html form with labels, select boxes, and radio buttons, you can use javascript to store the child elements of that form in a json string format. Here is an example: { "label": { "content": "This is a label" }, "textbox" ...

What steps can be taken to allow for the addition of multiple slick sliders using the same class on a single page?

When using the admin panel, the user has the ability to add multiple sliders to the page. How can all sliders with the same class be initialized? Is there a way to ensure that the control buttons for each slider are applied individually, instead of just f ...

Fixed position is used on elements that should always remain in the exact

I have a fixed menu on my website that is working perfectly fine. I also have a container (not using Bootstrap) that should stay fixed when it reaches the static menu. Everything is functioning as expected, except when I resize the window, the container se ...

Issue with Angular 7 application: Unable to read property 'ceil' of undefined

My project is running on Angular 7.0.2 and everything runs smoothly when the angular build optimization is set to false. However, when I change the setting to: "optimization": true The build completes successfully and my app starts without any issues. ...

JavaScript: create a new array by selecting elements from an existing array (similar to C#'s Select

If I have an array of 3 integers in C#, [1,2,3], I can transform that array into another with the .Select method like so: [1,2,3].Select(e => new { Id = e, Name = $"name:{e}"), resulting in a new array with 3 objects. Is there a way to achieve the same ...

"Applying CSS styles to highlighted text using jQuery - how can I do it

Struggling to style selected text with CSS? Here's what I've tried so far without success in Firefox. $(document).keyup(function(){ savedRange = selection.getRangeAt(0); $(savedRange).wrap('<span style="color:red"></span>' ...

Tips for identifying if the function "res.end()" has been executed or not

Is there a method to determine if the res.end function has been triggered? var http = require('http'); http.createServer(function (req, res) { some_function_may_called_end(req, res); // Is there a way to check for this? if(res.is_ended = ...

Unable to add an item from an array to the data property in Vue.js

When fetching data from Laravel, I use the following response: $unserialize = unserialize($import->field_names); return response()->json( $unserialize, 200 ) ; On Vue JS, I can view the response using: console.log(response); The data is displayed i ...

After executing the ng serve command, I encountered the following error message: "There has been an unhandled exception - Module '../dotjs/validate' could not be found."

**Oops! There was an unhandled exception: Module '../dotjs/validate' not found. **Here's a peek at my package.json file "dependencies": { "@angular/animations": "^8.1.1", ... "zone.js": "~0.9.1" }, " ...

Utilize jQuery to Dynamically Change Page Titles

While analyzing the source code of a WordPress plugin named Advanced Ajax Page Loader, I came across an interesting snippet. The author used the following code to update the page title after successful AJAX requests: data = data.split('<title>& ...

Trouble obtaining output from chrome.tabs in browser console

Currently, I am experimenting with the browser's console and attempting to retrieve all the details of the active tabs. In order to do so, I open the browser's console and input the following: However, I encountered the following error: VM713:1 ...

Stay updated with the complex query change feed in RethinkDB

When faced with a query like the following: r.db('universe') .table('Star') .getAll( r.db('universe').table('Ship').get(idShip)('idCurrentGalaxy'), {index: 'idGalaxy'} ) .changes ...

Angular HttpErrorResponse in Angular 2 and above fails to accurately reflect the correct status code when a timeout

Currently, I am utilizing httpClient.get() to initiate a REST call. The API has been configured to return a time out 504. Upon inspecting the Google devTools, I observed that the call is successfully made with a status of 504. However, during the debuggin ...

The dropdown feature fails to function properly when contained within a Bootstrap Popover

Utilizing jQuery v1.12.4, Bootstrap v3.3.7 and Bootstrap-Select v1.10.0. In a popover, I have 2 components. When the popover is opened, I am able to interact with the dropdowns but the selection does not change when clicking an option. You can view the e ...

Create a dropdown menu with Bootstrap 4 that pushes a popup below the navigation bar

I've incorporated a drop-down menu into my Bootstrap 4 navbar, but I'm facing an issue with its positioning. Instead of having the drop-down menu appear below the navbar as intended, it shows up somewhere else due to the default top attribute val ...

What is the best approach for capturing and managing a 406 error in VUEJS?

I am encountering a situation where I send the day and time to the API in order to verify if there is an opening in the schedule stored in the database. If no opening is found, the API responds with a 406 error code. As a result, I am seeing a 406 error ...

The hot loader is replicating code multiple times instead of conducting hot swapping

Every time I make a change in a component, webpack recompiles and React hot swaps the module over. However, I've noticed that my code runs multiple times after each hot module swapping occurrence. For example, if I make a change once, the functions ru ...

How to generate a new array in Angular by combining elements from two existing arrays for common items

I am currently working on a TypeScript function to compare two arrays and generate a third array containing the common items. For example: employees: any; offices: any; constructor() { this.employees = [ { fname: "John", lname: "James", sta ...