score:0

As i say in the comment the this in the IIFE is the window object. If you would like to create a self structuring object out of thin air and pass it as an argument you can do like these. I am not very familiar with HighCharts but i guess the second snippet is the correct data structure in which individual points have their own color definition.

var myObj = {
          xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        plotOptions: {
            series: {
                allowPointSelect: true
            }
        },
  
        series: [{
                  data: [1600, 3000, 400, 700, 1234, 765, 76],
                 color: []
                 }],
          init: function() {
                  this.series[0].color = this.series[0].data.map(e => e >= 1000 ? '#75ad74' : '#FF0000');
                  delete this.init;
                  return this;
                }
}.init();

console.log(myObj);

I guess this is the correct series[0].data structure for HighCharts.

var myObj = {
          xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        plotOptions: {
            series: {
                allowPointSelect: true
            }
        },
  
        series: [{
                  data: [1600, 3000, 400, 700, 1234, 765, 76],
                 }],
          init: function() {
                  this.series[0].data = this.series[0].data.map(e => e >= 1000 ? {y: e, color: '#75ad74'}
                                                                               : {y: e, color: '#FF0000'});
                  delete this.init;
                  return this;
                }
}.init();

console.log(myObj);

In real application you will provide this object definition as a parameter to the highcharts function.


Related Query

More Query from same tag