angular-highcharts icon indicating copy to clipboard operation
angular-highcharts copied to clipboard

Cannot read property 'options' of undefined

Open Iecy opened this issue 7 years ago • 10 comments

I am using the stock module to introduce charts in different models and will always report errors. I hope you have some demos to refer to; My mistake is as follows:

ComparePage.html:11 ERROR TypeError: Cannot read property 'options' of undefined at a.Chart.redraw (highcharts.js:247) at a.Chart. (stock.src.js:8540) at a.Chart.a.(:8100/anonymous function) (http://localhost:8100/build/0.js:1170:80) at a.Chart. (stock.src.js:8540) at a.Chart.a.(:8100/anonymous function) [as redraw] (http://localhost:8100/build/0.js:1170:80) at e.update (highcharts.js:341) at eachBaseSeries (stock.src.js:6520) at Array.forEach () at a.each (highcharts.js:28)

Now I have two modules A and B, and when I click on A to do stock, there's no problem, there's an error above in doing B module; This makes me very miserable. How do I use this tool to angular-highcharts

Iecy avatar Jul 31 '18 07:07 Iecy

Can you provide me a stackblitz or fiddle zo make this reproducible for me?

cebor avatar Jul 31 '18 11:07 cebor

Check if it is linking to a class property that is undefined. I got this error when defining my options Asyncly through an observable at a later time.

Jonathan002 avatar Aug 01 '18 08:08 Jonathan002

@cebor ok, I'll send you a copy later. I feel the problem lies in the stock module. I have no problem with the chart module;

Iecy avatar Aug 22 '18 08:08 Iecy

@cebor Hi, if you look at this demo it's already gone wrong in stock. Is my use wrong?

high.zip

Iecy avatar Aug 22 '18 11:08 Iecy

Hi @Iecy, I've encountered the same issue and fixed it by only loading highstock once:


import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts';
import * as highstock from 'highcharts/modules/stock.src';

let loaded = false;
export function highchartsModules() {
  if (!loaded) {
    loaded = true;
    return [highstock];
  }
  return [];
}
@NgModule({
  imports: [ChartModule],
  declarations: [MyChartComponent],
  exports: [MyChartComponent],
  providers: [{ provide: HIGHCHARTS_MODULES, useFactory: highchartsModules }],
})
export class MyChartModule {}

Where MyChartComponent is your custom component that uses angular-highcharts.

Hope it'll help you :)

StephaneTrebel avatar Sep 13 '18 08:09 StephaneTrebel

@StephaneTrebel nice catch, im looking into this and resolve it in the library.

cebor avatar Sep 14 '18 08:09 cebor

@StephaneTrebel Thank you very much. A very effective solution;

Iecy avatar Sep 22 '18 08:09 Iecy

@cebor Nice, Come on; Hope gets better and better;

Iecy avatar Sep 22 '18 08:09 Iecy

@cebor I too encountered the same issue as @Iecy gets. I have tried the solution given by @StephaneTrebel. But Still, it's not working; getting following error

TrendsComponent.html:74 ERROR TypeError: Cannot read property 'options' of undefined at a.Chart.redraw (highcharts.js:247) at a.Chart. (stock.src.js:8540) at a.Chart.a.(:4200/anonymous function) (http://localhost:4200/dashboard-dashboard-module~trends-trends-module.js:503:80) at a.Chart. (stock.src.js:8540) at a.Chart.a.(:4200/anonymous function) [as redraw] (http://localhost:4200/dashboard-dashboard-module~trends-trends-module.js:503:80) at e.update (highcharts.js:341) at eachBaseSeries (stock.src.js:6520) at Array.forEach () at a.each (highcharts.js:28) at Navigator.updateNavigatorSeries (stock.src.js:6475)

naresh33 avatar Oct 14 '18 05:10 naresh33

@naresh33 I also had the same issue before I have updated my code with the @StephaneTrebel solution. Can you show the code of all of your modules where did you use highcharts / highstock.

yash27 avatar Oct 15 '18 08:10 yash27