2017-05-11 52 views
1

我有一個代碼箭頭符號在Internet Explorer中不工作的data.reduce

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; 
       },[]); 

以上是我的完整代碼,我現在用箭頭符號。該代碼在IE瀏覽器以外的所有瀏覽器中工作正常。當我GOOGLE時,我發現箭頭符號在IE中不起作用。

這是我的代碼https://jsfiddle.net/y1s6pttt/請在IE

檢查任何人都可以請給一個解決方案。有沒有其他的方式來編寫代碼。

請幫忙!!

+1

_「任何人都可以請給這個解決方案」_嗯......只需使用一個普通的舊函數(){...} Oo – Andreas

+0

爲什麼不嘗試使用babel – user93

+0

我是新來的jquery 。這是我在谷歌找到的代碼。我試圖重寫,但我無法將其轉換爲舊功能。你能幫我 –

回答

0

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":"","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(/([[email protected]#$%^&*()_+=`{}\[\]\|\\:;'<>,.\/? ])+/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>

+0

我知道IE瀏覽器不支持箭頭功能,但是這個 –

+0

使用正常的js函數的解決方案可能是修復;-) – MehulJoshi

+0

我不'知道正確的語法。請您將其寫下功能 –

0

Internet Explorer不支持許多功能ES6。但是,您仍然可以在ES6中編寫代碼,並使用像Babel這樣的轉換器將您的代碼轉換爲ES5,以便它可以在舊版瀏覽器上運行。

相關問題