1

I have a code

  data = JSON.parse('<?php echo $monthlyParticipation; ?>'),

  months1 = data.reduce((p,c) => ~p.indexOf(c.months) ? p : p.concat(c.months),[]),

  series = data.reduce((p,c) => { var f = p.find(f => f.name == c.project_title);
                               !!f ? f.data[months1.indexOf(c.months)] = c.amount*1
                                  : p.push({name: c.project_title, id:c.project_title,
                                     data: (new Array(months1.length)).fill(0).map((e,i) => i === months1.indexOf(c.months) ? c.amount*1 : e)});

                          return p; 
                 },[]);

Above is my complete code where I am using arrow notations. The code is working fine in all the browsers excepts IE. When I googled I found that arrow notations do not work in IE.

This is my code https://jsfiddle.net/y1s6pttt/ please check in IE

Can anyone please give a solution for this. Is there any other way to write the code.

Please help!!

rji rji
  • 697
  • 3
  • 17
  • 37

2 Answers2

0

Internet explorer does not support many ES6 features. But you can still write your code in ES6 and use transpilers like Babel to convert your code to ES5 so that it can run on older browsers.

user93
  • 1,866
  • 5
  • 26
  • 45
-1

function newFilledArray(len, val) {
  var rv = new Array(len);
  while (--len >= 0) {
    rv[len] = val;
  }
  return rv;
}
data = JSON.parse('[{"project_ref_id":"479","project_title":"Environment project","estimated_project_cost":"0","amount":"0","months":"Dec-2016"},{"project_ref_id":"479","project_title":"Environment project","estimated_project_cost":"0","amount":"0","months":"Jan-2017"},{"project_ref_id":"479","project_title":"Environment project","estimated_project_cost":"0","amount":"0","months":"Feb-2017"},{"project_ref_id":"479","project_title":"Environment project","estimated_project_cost":"7845963210","amount":"85964710","months":"Mar-2017"},{"project_ref_id":"479","project_title":"Environment project","estimated_project_cost":"0","amount":"0","months":"Apr-2017"},{"project_ref_id":"479","project_title":"Environment project","estimated_project_cost":"0","amount":"0","months":"May-2017"}]'),
  months1 = data.reduce(function(p, c) {
    return ~p.indexOf(c.months) ? p : p.concat(c.months)
  }, []),
  series = data.reduce(function(p, c) {
    var f = undefined;
    console.log(p);
    p.map(function(x) {
      if (x.name == c.project_title) {
        f = x;
      }
    });

    !!f ? f.data[months1.indexOf(c.months)] = c.amount * 1 :
      p.push({
        name: c.project_title,
        id: c.project_title,
        data: (
          Array.apply(null, new Array(months1.length)).map(Number.prototype.valueOf, 0)
          .map(
            function(e, i) {
              return i === months1.indexOf(c.months) ? c.amount * 1 : e
            }
          ))
      });
    return p;
  }, []);
var chart1 = new Highcharts.Chart({
  chart: {
    renderTo: 'container1'
  },
  xAxis: {
    categories: months1,
    title: {
      text: 'Months'
    }
  },
  yAxis: {
    min: 0,
    title: {
      text: 'Rupees'
    }
  },
  title: {
    text: ''
  },
  credits: {
    enabled: false
  },
  plotOptions: {
    series: {
      events: {
        legendItemClick: function(event) {
          var selected = this.index;
          var allSeries = this.chart.series;
          $.each(allSeries, function(index, series) {
            selected == index ? series.show() : series.hide();
          });
          return false;
        }
      }
    }
  },
  series: series,
}, function(chart1) {


  $.each(chart1.series, function(i, serie) {
    var pname = serie.name;
    var pjname = pname.replace(/([~!@#$%^&*()_+=`{}\[\]\|\\:;'<>,.\/? ])+/g, '').replace(/^(-)+|(-)+$/g, '');
    var chartcolor = $('#container1 .highcharts-series-' + i + ' path').attr('stroke');
    if (chartcolor == 'rgba(192,192,192,0.0001)') {
      chartcolor = '#7cb5ec';
    }
    chart1.series[i].graph.attr({
      stroke: chartcolor
    });
    var $customLegend = $('.prj-label1' + pjname).css('background-color', chartcolor);
  });
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container1" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
MehulJoshi
  • 879
  • 8
  • 19