Open warash opened 7 years ago
Hi I do not know if the issue is the same but some how when new option object is generated the formatter function is not overridden while the data is. I did a fork in plunker. Here is the link http://plnkr.co/edit/Ledq09fuaDRV0HBL7fI0?p=preview and code:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { NgModule, Component } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { ChartModule } from 'angular2-highcharts';
@Component({
selector: 'my-app',
styles: [ chart { display: block; }
],
template: <chart [options]="options"></chart> <button (click)="changeCurrency()">Show dollar values</button>
})
class AppComponent {
constructor() {
this.options = this.getOptions('€');
}
changeCurrency(){
this.options = this.getOptions('$');
}
getOptions(currency){
let euros = [29.9, 71.5, 106.4, 129];
let dollars = [50, 40, 30, 10];
return {
title : { text : 'simple chart' },
plotOptions: {
series: {
dataLabels: {
enabled: true,
formatter : function(){
return currency + this.y;
}
}
}
},
series: [{
data: '$' == currency ? dollars : euros,
}]
};
}
options: Object;
}
@NgModule({ imports: [BrowserModule, ChartModule], declarations: [AppComponent], bootstrap: [AppComponent] }) class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);
I have been wrestling with this same issue. using observables allows me to dynamically update the chart options, but formatter functions and a handful of other properties remain. Has anyone had success getting around this yet?
EDIT -- was able to fix the issue by checking out the fixes on @warash 's profile. Thank you for going ahead and taking care of this bug. it had been driving me nuts.
hi Inside src/ChartComponent.ts there is initialized prop baseOption which then is used as default options merged with client options.. its something wrong with this merging "assignTo" methods because after one usage of chart with user options then when options changed baseOption object is holding some data from first usage with useroptions.. solution for this i have made in my fork branch is to create everytime new object baseoptions instead initializing it once on init component... look on my fork it solved issue.