Legend in AMCharts 5 remains visible even after deleting the chart

I integrated an AMCharts 5 chart into my Angular application that requires removal upon a specific action. However, even after deleting the chart, the legend tooltips continue to be displayed.

Below is the code snippet used to generate the chart :

this.rootTest = am5.Root.new('test')
this.chartTest = this.rootTest.container.children.push(
  am5xy.XYChart.new(this.rootTest, {
    panY: false,
    layout: this.rootTest.verticalLayout
  })
);
let xRenderer = am5xy.AxisRendererX.new(this.rootTest, { minGridDistance: 30 });
let xAxis = this.chartTest.xAxes.push(
  am5xy.CategoryAxis.new(this.rootTest, {
    renderer: xRenderer,
    categoryField: "category"
  })
);
let yAxis = this.chartTest.yAxes.push(
  am5xy.ValueAxis.new(this.rootTest, {
    min: 0,
    renderer: am5xy.AxisRendererY.new(this.rootTest, {})
  })
);
                    
let series = this.chartTest.series.push(
  am5xy.LineSeries.new(this.rootTest, {
    name: 'Serie',
    xAxis: xAxis,
    yAxis: yAxis,
    valueYField: 'yValue',
    categoryXField: "category",
    tooltip: am5.Tooltip.new(this.rootTest, {
      labelText: "{name} {categoryX} : [bold]{valueY}[/]"
    })
  })
);

xAxis.data.setAll([{ category: 'category1' }, { category: 'category2' }])
series.data.setAll([{ category: 'category1', yValue: 10 }, { category: 'category2', yValue: 20 }])
                                
this.chartTest.set("cursor", am5xy.XYCursor.new(this.rootTest, {
  behavior: "zoomX"
}));
                                
let legend = this.chartTest.children.push(am5.Legend.new(this.rootTest, {}));
legend.data.setAll(this.chartTest.series.values);

When attempting to remove the chart, I use the following line of code :

this.rootTest.container.children.clear();

This issue only arises when a cursor is added to the chart. Is there a method to eliminate these tooltips?

View before removing the chart View after removing the chart

Answer №1

Dealing with a similar issue before, I was able to find a solution that worked for me. I suggest taking a look at this particular problem and exploring the usage of the root.dispose() function.

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

Encountering a TypeScript error when using Redux dispatch action, specifically stating `Property does not exist on type`

In my code, there is a redux-thunk action implemented as follows: import { Action } from "redux"; import { ThunkAction as ReduxThunkAction } from "redux-thunk"; import { IState } from "./store"; type TThunkAction = ReduxThunk ...

WebStorm Angular 13 async pipe issue: Missing import statement

Recently, I updated to Angular 13 and noticed that in my WebStorm, the async pipe is now showing up as red with an error message saying: Missing require() statement https://i.stack.imgur.com/qNRui.png In addition, all directives are displaying a warnin ...

Patience required for Angular to retrieve data from API call

I am currently struggling with getting my Donut chart to load properly with data returned from three separate API calls. I have initialized the chart and the API call functions in ngOninit(). However, it seems like my chart is not loading. I understand tha ...

The perplexing behavior of RxJS Observables with Mongo Cursors

Recently, I've been working on converting a mongo cursor into an observable using my own RxJS implementation. Despite finding numerous solutions online, I wanted to challenge myself by creating one from scratch. I would greatly appreciate it if someo ...

I am currently making use of the Material UI accordion component and I would prefer for it to not collapse unless I specifically click on the expandIcon

I have been utilizing the Material UI accordion component and am currently struggling to find a solution that prevents the panel from collapsing when it is clicked. Ideally, I would like to manage the opening and closing of the panel solely through click ...

New Problem Arises with Angular Mat Table: Added Rows Disappear When Another Row is Deleted

I have implemented a feature where users can add rows to a table by clicking a button. dataSource = new MatTableDataSource(this.ELEMENT_DATA); this.ELEMENT_DATA.push(...); this.table.renderRows(); Additionally, users can delete rows by filtering the data ...

Mastering the art of calculating month differences on TypeScript dates in an Angular environment

Currently, I am working with Angular 7. Suppose I have a fixed rate X, for example, an amount I need to pay each month. Now, if I have two specified dates startDate and endDate, I want to calculate the total payment due for this given time period. To prov ...

Encountering difficulty importing TypeScript files dynamically within a Deno executable

When attempting to import a file from aws in an exe using its public link based on user input, I am facing difficulties For example, I generated my exe with the command below deno compile --allow-all main.ts Users execute this exe using commands like ./e ...

Distributing utility functions universally throughout the entire React application

Is there a way to create global functions in React that can be imported into one file and shared across all pages? Currently, I have to import helper.tsx into each individual file where I want to use them. For example, the helper.tsx file exports functio ...

Implementing a Loading Spinner with Angular4's HttpClient Interceptor

Within this code snippet, you will find the interceptor I created to manage the spinner directly through the interceptor itself. @Injectable() export class ApiInterceptor implements HttpInterceptor { constructor(private _globalSpinnerService: GlobalSp ...

What steps should we take to ensure that the container beside the fixed left navigation bar is responsive?

Currently, I am working on creating a user interface that features a fixed navigation bar on the left hand side and a responsive content window. Here is what I have implemented so far: <div style="width: 15%; float: left; display: inline;"> <na ...

Building a filter for a union type in TypeScript: a step-by-step guide

Allow me to present an example to demonstrate my current objective. const v1: { type: "S"; payload: string } = { type: "S", payload: "test" }; const v2: { type: "N"; payload: number } = { type: "N", payload: 123 }; type Actions = typeof v1 | typeof v2; ...

The beta version of Angular 2.0 introduces the BrowserDomAdapter for easy access to the DOM

I have a Component in Angular 2.0 that is attempting to utilize the DOM Adapter API from Angular's BrowserDomAdapter documentation. The initialization of this DomAdapter can be found here. However, I am uncertain about whether the Dom Adapter needs t ...

Issue encountered when attempting to save items in the browser's local storage

I'm encountering an issue: ERROR Error: Uncaught (in promise): DataCloneError: Failed to execute 'put' on 'IDBObjectStore': Position object could not be cloned. Error: Failed to execute 'put' on 'IDBObjectStore& ...

Post request in limbo

Looking for a way to delay post requests in Angular before they are sent? I've tried using pipe(delay(xxx)) and setTimeout, but haven't had any luck. Any suggestions on how to solve this issue? ...

The functionality of Angular 4's ngStyle sum operates as a string instead of a number

<div class="scroll-element-content" [ngStyle]="{'width.px': (this.width + this.trackWidth)}"> With this.width set to 400 and this.trackWidth set to 8: The combined width of .scroll-element-content will be 4008 (since the sum is treated as ...

Changing a table cell's value when a button is clicked using Angular

I'm working with a bootstrap table that includes a button and a textbox above it. After entering a number in the textbox and clicking the generate button, I need to update the "Bill Amount" column for each row with the value from the textbox. How can ...

The vertical scrolling functionality of the MUI DataGrid in Safari may occasionally fail to work

Utilizing the <Box> component from MUI core and the <DataGrid> component from MUIX, along with some other components, I have created a data grid that has the following appearance: https://i.sstatic.net/Gc8sP.png When the number of rows exceed ...

send the checkbox control's model value back to the parent control in Vue3

I've implemented a wrapper control for checkboxes that closely resembles my textbox control. This approach ensures consistent validation and design throughout the application. While I was successful in getting it to work for textboxes, I encountered s ...

Adding a fresh element to an object array in TypeScript

How can we add a specific value to an array of objects using TypeScript? I am looking to insert the value 1993 into each "annualRentCurrent" property in the sample object. Any suggestions on how to achieve this in TypeScript or Angular? Thank you! #Data ...