赞
踩
npm install echarts@4.9.0
附:打包时发现echarts地图不显示,后查看china.js后发现下边这段代码的问题,注释掉就好了
else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
console.log(2)
// CommonJS
factory(exports, require('echarts'));
} else {
console.log(3)
// Browser globals
factory({}, root.echarts);
}
<template> <div :class="className" id="Chart" :style="{ height: height, width: width }" /> </template> <script> //引入中国地图数据 (*********重中之重) import "../map/js/china"; import * as echarts from "echarts"; require("echarts/theme/macarons"); // echarts theme import { debounce } from "@/utils"; export default { props: { className: { type: String, default: "chart", }, width: { type: String, default: "100%", }, height: { type: String, default: "450px", }, // Industry:{ // type: Array, // default:[], // } }, data() { return { chart: null, }; }, mounted() { this.initChart(); this.__resizeHandler = debounce(() => { if (this.chart) { this.chart.resize(); } }, 100); window.addEventListener("resize", this.__resizeHandler); }, beforeDestroy() { if (!this.chart) { return; } window.removeEventListener("resize", this.__resizeHandler); this.chart.dispose(); this.chart = null; }, methods: { // 渲染echarts-地图 initChart() { let dataList = [ { name: "南海诸岛", value: 0, eventTotal: 100, specialImportant: 10, import: 10, compare: 10, common: 40, specail: 20, }, { name: "北京", value: 0, }, { name: "天津", value: 0, }, { name: "上海", value: 10, }, { name: "重庆", value: 20, }, { name: "河北", value: 30, }, { name: "河南", value: 0, }, { name: "云南", value: 0, }, { name: "辽宁", value: 0, }, { name: "黑龙江", value: 40, }, { name: "湖南", value: 0, }, { name: "安徽", value: 0, }, { name: "山东", value: 50, }, { name: "新疆", value: 0, }, { name: "江苏", value: 0, }, { name: "浙江", value: 0, }, { name: "江西", value: 0, }, { name: "湖北", value: 0, }, { name: "广西", value: 0, }, { name: "甘肃", value: 0, }, { name: "山西", value: 0, }, { name: "内蒙古", value: 0, }, { name: "陕西", value: 0, }, { name: "吉林", value: 0, }, { name: "福建", value: 0, }, { name: "贵州", value: 0, }, { name: "广东", value: 0, }, { name: "青海", value: 0, }, { name: "西藏", value: 80, }, { name: "四川", value: 0, }, { name: "宁夏", value: 0, }, { name: "海南", value: 0, }, { name: "台湾", value: 0, }, { name: "香港", value: 0, }, { name: "澳门", value: 0, }, ]; let options = { tooltip: {// tooltip 提示框组件 background: '', trigger: 'item', // 触发类型, 'item'数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。 'axis'坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。 triggerOn: 'mousemove', // 提示框触发的条件,'mousemove'鼠标移动时触发。'click'鼠标点击时触发。'mousemove|click'同时鼠标移动和点击时触发。'none'不在 'mousemove' 或 'click' 时触发 showContent: true, //是否显示提示框浮层 alwaysShowContent: false, //是否永远显示提示框内容 showDelay: 0, //浮层显示的延迟,单位为 ms hideDelay: 50, //浮层隐藏的延迟,单位为 ms enterable: false, //鼠标是否可进入提示框浮层中 confine: false, //是否将 tooltip 框限制在图表的区域内 transitionDuration: 0.1, //提示框浮层的移动动画过渡时间,单位是 s,设置为 0 的时候会紧跟着鼠标移动 // position: ['50%', '50%'], //提示框浮层的位置,默认不设置时位置会跟随鼠标的位置,[10, 10],回掉函数,inside鼠标所在图形的内部中心位置,top、left、bottom、right鼠标所在图形上侧,左侧,下侧,右侧, backgroundColor: "#FFFFFF", //标题背景色 borderColor: "#FFFFFF", //边框颜色 borderWidth: 0, //边框线宽 padding: [5, 10], //图例内边距,单位px 5 [5, 10] [5,10,5,10] textStyle: 'mytextStyle', //文本样式 */ formatter:function(params){//提示框浮层内容格式器,支持字符串模板和回调函数两种形式 return params.name+'国资委<br />每股ESG:'+params.value+'<br />排名:1'; } }, visualMap: { show: true, type: "continuous", min: 0, max: 100, left: 0, botton: 0, itemGap: 0, showLabel: true, realtime: false, itemWidth: 12, itemHeight: 90, calculable: true, }, visualMap:{ min:0, max:100, inRange:{ color:['#e0ffff', '#006edd'] //控制颜色渐变的范围 }, calculable: true //出现滑块 }, geo: { map: "china", scaleLimit: { min: 1, }, zoom: 1, roam: true, top: 30, bottom: 10, label: { normal: { show: true, fontSize: "8", color: "rgba(0,0,0)", }, }, itemStyle: { normal: { borderColor: "rgba(0, 0, 0, 0.2)", }, emphasis: { areaColor: "#f2d5ad", shadowOffsetX: 0, shadowOffsetY: 0, borderWidth: 0, }, }, }, series: [ { // name: "地区分布", type: "map", // roam: true, geoIndex: 0, data: dataList, }, ], }; // let mapWrapper = document.getElementById("Chart"); this.chart = echarts.init(this.$el, "macarons"); this.chart.setOption(options); this.chart.on('click', (params) => { console.log("params==",params) this.$emit('clickChart',params) // this.getAlertList(parseFloat(this.risk_value), params.name) }) }, }, }; </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。