amcharts / amcharts5

The newest, fastest, and most advanced amCharts charting library for JavaScript and TypeScript apps.
Other
353 stars 95 forks source link

Unable to save Custom Indicators in Data Save Control #1249

Closed workingbuddy10 closed 10 months ago

workingbuddy10 commented 10 months ago

I am trying to save the custom indicator which I made in the data save control.

Custom indicator name : My indicator Link to check : https://codepen.io/Ansh-m-the-reactor/pen/GRwawNg

martynasma commented 10 months ago

This is because JSON parser does not know custom classes, and thus cannot restore it.

We will need to figure out a way to register custom classes for JSON parser.

At this point there's nothing that can be done by you. We'll need to implement it on our end.

Will keep you posted.

workingbuddy10 commented 10 months ago

Sure no issues!!

martynasma commented 10 months ago

A way to register custom Indicator class will be added in the next version. I will notify you here when it's out.

In the interim, I suggest you fix issues with your code.

1) The IndicatorControl callback that adds new indicator needs to return Indicator instance, not push it into stockChart.indicators. By pushing it, you will get the indicator serialized and restored twice.

2) Your indicator is meant to display in the same panel as the main series, yet it extends ChartIndicator which results in error. It should extend Indicator.

workingbuddy10 commented 10 months ago

So I should change the class to this, isn't ?

// Define indicator class
class MyIndicator extends am5stock.Indicator {

@martynasma

martynasma commented 10 months ago

Correct.

workingbuddy10 commented 10 months ago

Thank you @martynasma !!!!

martynasma commented 10 months ago

Fixed in 5.7.2.

[5.7.2] - 2023-12-22

Added

Changed

Fixed

Full change log.

Download options.

Make sure you clear your browser cache after upgrading. And feel free to contact us again if you are still experiencing this issue.

martynasma commented 10 months ago

For it to work properly you will need to register your custom indicator class:

am5stock.registerClass("MyIndicator", MyIndicator);

Example: https://codepen.io/team/amcharts/pen/GReRmbr/c84b1bf62d0f736a44b3a37382110923?editors=0010

workingbuddy10 commented 10 months ago

@martynasma In the given example the chart is not getting plotted, please check it once!

martynasma commented 10 months ago

Did you register your custom class as suggested above?

workingbuddy10 commented 10 months ago

Yes @martynasma, can you try & test it in the below codepen? image

https://codepen.io/team/amcharts/pen/GReRmbr/c84b1bf62d0f736a44b3a37382110923?editors=0010

martynasma commented 10 months ago

OK, sorry, I failed to mention another important detail. The custom indicator class needs to also have className set on it:

class MyIndicator extends am5stock.Indicator {
  className = "MyIndicator";
  // ...
}
workingbuddy10 commented 10 months ago

OK, sorry, I failed to mention another important detail. The custom indicator class needs to also have className set on it:

class MyIndicator extends am5stock.Indicator {
  className = "MyIndicator";
  // ...
}

It is also there, you can checkout the codepen link given, test it out.

image

@martynasma

martynasma commented 10 months ago

OK, so CodePen is not good for testing it, because it changes the URL of its iframe, and indicators are saved based on URL.

So either you test it outside CodePen, or you specify your own storageId: https://www.amcharts.com/docs/v5/charts/stock/toolbar/data-save-control/#Storage_scope