Error accessing object property in module

0

Well, I'm running some tests with JavaScript modules, unfortunately there's a type Uncaught TypeError error when trying to set the property, setOption, of the mychart object. This is passed as a parameter to a class that is in another module. The current code looks like this:

App.js

import {
  echart,
  theme,
  option
} from './module-chart';

import {
  ChartController
} from './module-chart-controller';

let mychart = echart.init(document.getElementById('main'), theme);
mychart.setOption(option);

let chartController = new ChartController(mychart);
chartController.animateChart();

module-chart-controller.js

class ChartController{

  constructor(chart){
    this.mychart = chart;
  }

  animateChart() {
    let intervalo = setInterval(function() {
      concentrationOfAandB = getObjectConcentrationOfAandB();
      dataA.push(concentrationOfAandB.concentrationOfA);
      dataB.push(concentrationOfAandB.concentrationOfB);
      this.mychart.setOption({
        series: [{
            data: data5,
            animationDuration: 1000
          },
          {
            data: data4,
            animationDuration: 1000
          }
        ]
      });
    }, 1900);
    setTimeout(function() {
      clearInterval(intervalo);
    }, 40000);
  }
}
export {ChartController};

When I put the module-chart-controller.js code in the App.js file, no error occurs.

This is the error message that is displayed on the console: Uncaught TypeError: Can not read property 'setOption' of undefined acknowledging error in module-chart-controller.js file

Thanks in advance for your attention!

    
asked by anonymous 08.02.2018 / 04:59

0 answers