zhengpz
2021-07-28 4fe87ff1f2bd753339d375f31357075e711ce307
src/views/home/indexEchart.js
@@ -1,3 +1,5 @@
import * as echarts from "echarts";
import nc from '../../../public/nc.json';
function left1Data(allData) {
  let nameArr = [];
  let data1 = [];
@@ -45,7 +47,7 @@
      }
    },
    grid: {
      top:'5%',
      top: '5%',
      left: "5%",
      right: "6%",
      bottom: "10%",
@@ -151,7 +153,7 @@
      }
    },
    grid: {
      top:'5%',
      top: '5%',
      left: "5%",
      right: "6%",
      bottom: "15%",
@@ -182,7 +184,7 @@
        name: "持证人数",
        type: "bar",
        // barWidth:30,
        barWidth: 20,
        barWidth: 15,
        stack: "total",
        emphasis: {
          focus: "series"
@@ -412,7 +414,7 @@
    var key = key || "value";
    var res = [];
    if (array) {
      array.forEach(function(t) {
      array.forEach(function (t) {
        res.push(t[key]);
      });
    }
@@ -558,10 +560,201 @@
  };
  return option;
}
function middleData(allData, type) {
  var ncMap = nc;
  // var convertData = function (allData) {
  //   var res = [];
  //   for (var i = 0; i < data.length; i++) {
  //     var geoCoord = geoCoordMap[data[i].name];
  //     if (geoCoord) {
  //       res.push({
  //         name: data[i].name,
  //         value: geoCoord.concat(data[i].value)
  //       });
  //     }
  //   }
  //   return res;
  // };
  let name = '';
  let label = '';
  let symbolUrl = '';
  let geoData = []
  allData['table'].forEach((item, i) => {
    let obj = {};
    if (type === 1) {
      name = '保安员名称';
      label = '名称';
      symbolUrl = require('@/assets/img/people.png')
      obj = {
        name: item.name,
        value: allData['geoData'][i]
      }
    } else if (type === 2) {
      name = '押运车辆';
      label = '押运车辆车牌号';
      symbolUrl = require('@/assets/img/car.png')
      obj = {
        name: item.carNum,
        value: allData['geoData'][i]
      }
    } else if (type === 3) {
      name = '枪支';
      label = '枪支编号';
      symbolUrl = require('@/assets/img/gun.png')
      obj = {
        name: item.number,
        value: allData['geoData'][i]
      }
    }
    geoData.push(obj)
  })
  echarts.registerMap('ncMap', ncMap);
  // echarts.registerMap('chinaMapOutline', chinaMapOutline);
  let option = {
    // backgroundColor: '#181F4E',
    // tooltip: {
    //   trigger: 'item',
    // },
    tooltip: {
      trigger: 'item',
      formatter: function (params) {
        if (typeof (params.value)[1] == "undefined") {
          return params.name;
        } else {
          return label + ' : ' + params.name;
        }
      },
      backgroundColor: "#031952", //设置背景图片 rgba格式
      color: "#fff",
      borderWidth: "0", //边框宽度设置1
      // borderColor: "gray", //设置边框颜色
      textStyle: {
        color: "#fff" //设置文字颜色
      },
    },
    geo: {
      // silent: true,
      map: 'ncMap',
      show: true,
      zoom: 1.14,
      top: '10%',
      label: {
        normal: {
          show: false,
          textStyle: {
            color: '#fff'
          }
        },
        emphasis: {
          textStyle: {
            color: '#fff'
          }
        }
      },
      roam: true,
      itemStyle: {
        normal: {
          areaColor: 'rgba(0,255,255,.02)',
          borderColor: '#00ffff',
          borderWidth: 1.5,
          shadowColor: '#00ffff',
          shadowOffsetX: 0,
          shadowOffsetY: 4,
          shadowBlur: 10,
        },
        emphasis: {
          color: 'transparent', //悬浮背景
          textStyle: {
            color: '#fff'
          }
        }
      }
    },
    series: [
      {
        map: 'ncMap',
        // silent: true,
        type: 'map',
        geoIndex: 0,
        // aspectScale: 0.75, //长宽比
        zoom: 1.14,
        label: {
          normal: {
            show: false,
            textStyle: {
              color: '#fff'
            }
          },
          emphasis: {
            textStyle: {
              color: '#fff'
            }
          }
        },
        top: '10%',
        roam: true,
        itemStyle: {
          normal: {
            areaColor: 'rgba(0,255,255,.02)',
            borderColor: '#00ffff',
            borderWidth: 1.5,
            shadowColor: '#00ffff',
            shadowOffsetX: 0,
            shadowOffsetY: 4,
            shadowBlur: 10,
          },
          emphasis: {
            areaColor: 'transparent', //悬浮背景
            textStyle: {
              color: '#fff'
            }
          }
        }
      },
      {
        name: name,
        type: 'scatter',
        coordinateSystem: 'geo',
        // roam: false,
        symbol: 'image://' + symbolUrl,
        symbolSize: [30, 30],
        label: {
          normal: {
            show: false,
            textStyle: {
              color: '#fff',
              fontSize: 9,
            },
            // formatter(value) {
            //   return value.data.value[0]
            // }
          }
        },
        itemStyle: {
          normal: {
            color: '#FF0000', //标志颜色
          }
        },
        data: geoData,
        showEffectOn: 'render',
        rippleEffect: {
          brushType: 'stroke'
        },
        hoverAnimation: true,
        zlevel: 1
      }
    ]
  }
  return option
}
export default {
  left1Data,
  left2Data,
  right1Data,
  right2Data,
  right3Data
  right3Data,
  middleData
};