鍍金池/ 問答/HTML/ Cannot read property 'concat' of undefin

Cannot read property 'concat' of undefined

var myChart = echarts.init(document.getElementById('main'));

var geoCoordMap = {

'上海': [121.4648,31.2891],
'東莞': [113.8953,22.901],
'東營': [118.7073,37.5513],
'中山': [113.4229,22.478],
'臨汾': [111.4783,36.1615],
'臨沂': [118.3118,35.2936],
'丹東': [124.541,40.4242],
'麗水': [119.5642,28.1854],
'烏魯木齊': [87.9236,43.5883],
'佛山': [112.8955,23.1097],

};

var BJData = [
[{name:'成都'},{name:'濰坊',value:5}],
[{name:'濰坊'},{name:'西寧',value:5}],
[{name:'西寧'},{name:'溫州',value:5}],
[{name:'溫州'},{name:'東莞',value:5}],
[{name:'東莞'},{name:'汕頭',value:5}],
[{name:'汕頭'},{name:'福州',value:5}],
[{name:'廊坊'},{name:'廊坊',value:5}]
];

var planePath = 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z';

var convertData = function (data) {

var res = [];
for (var i = 0; i < data.length; i++) {
    var dataItem = data[i];
    var fromCoord = geoCoordMap[dataItem[0].name];
    var toCoord = geoCoordMap[dataItem[1].name];
    if (fromCoord && toCoord) {
        res.push({
            fromName: dataItem[0].name,
            toName: dataItem[1].name,
            coords: [fromCoord, toCoord]
        });
    }
}
return res;

};

var color = ['#a6c84c', '#ffa022', '#46bee9'];
var series = [];
[['北京', BJData]].forEach(function (item, i) {

series.push({
        name: item[0] + ' Top10',
        type: 'lines',
        coordinateSystem: 'bmap',//百度地圖
        // coordinateSystem: 'geo',// echarts3的地圖
        zlevel: 1,
        effect: {
            show: true,
            period: 6,
            trailLength: 0.7,
            color: '#fff',
            symbolSize: 3
        },
        lineStyle: {
            normal: {
                color: color[i],
                width: 0,
                curveness: 0.2
            }
        },
        data: convertData(item[1])
    },
    {
        name: item[0] + ' Top10',
        type: 'lines',
        coordinateSystem: 'bmap', //百度地圖
        // coordinateSystem: 'geo', // echarts3的地圖
        zlevel: 2,
        effect: {
            show: true,
            period: 6,
            trailLength: 0,
            symbol: planePath,
            symbolSize: 15
        },
        lineStyle: {
            normal: {
                color: color[i],
                width: 1,
                opacity: 0.4,
                curveness: 0.2
            }
        },
        data: convertData(item[1])
    },
    {
        name: item[0] + ' Top10',
        type: 'effectScatter',
        coordinateSystem: 'bmap',//百度地圖
        // coordinateSystem: 'geo',// echarts3的地圖
        zlevel: 2,
        rippleEffect: {
            brushType: 'stroke'
        },
        label: {
            normal: {
                show: true,
                position: 'right',
                formatter: ''
            }
        },
        symbolSize: function (val) {
            return val[2] / 8;
        },
        itemStyle: {
            normal: {
                color: color[i]
            }
        },
        data: item[1].map(function (dataItem) {
            return {
                name: dataItem[1].name,
                value: geoCoordMap[dataItem[1].name].concat([dataItem[1].value])
            };
        })
    });

});

option = {

backgroundColor: '#404a59',
title : {
    text: '模擬遷徙',
    subtext: '數(shù)據(jù)純屬虛構(gòu)',
    left: 'center',
    textStyle : {
        color: '#fff'
    }
},
tooltip : {
    trigger: 'item'
},
legend: {
    orient: 'vertical',
    top: 'bottom',
    left: 'right',
    data:['北京 Top10', '上海 Top10', '廣州 Top10'],
    textStyle: {
        color: '#fff'
    },
    selectedMode: 'single'
},
dataRange: {
    min: 0,
    max: 100,
    x: 'right',
    calculable: true,
    color: ['#ff3333', 'red'],
    textStyle: {
        color: '#fff'
    }
},
bmap: {
    center: [115.97, 29.71],
    zoom: 5,
    roam: true
},
//  geo: {
//     map: 'world',
//     label: {
//         emphasis: {
//             show: false
//         }
//     },
//     roam: true,
//     itemStyle: {
//         normal: {
//             areaColor: '#323c48',
//             borderColor: '#404a59'
//         },
//         emphasis: {
//             areaColor: '#2a333d'
//         }
//     }
// },
series: series

};

myChart.setOption(option);

可是在這一行報錯,我看了官網(wǎng)的是這樣寫的沒有錯啊,不知道我這里錯了哪里..................

clipboard.png

回答
編輯回答
吢涼

拋出的錯誤意思是geoCoordMap[dataItem[1].name]沒有concat這個方法。

一般來講,可能的原因是你map中的某一個geoCoordMap[dataItem[1].name]undefined...。

在你map的函數(shù)中,return之前,console.log(dataItem[1].name, geoCoordMap[dataItem[1].name])就知道是哪個數(shù)據(jù)出問題了。

2017年12月6日 03:28
編輯回答
裸橙

輸出下geoCoordMap[dataItem[1].name]的值,應(yīng)該是undefined
你的第一個濰坊geoCoordMap就沒有

2017年10月3日 11:23