博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Vue中使用echarts绘制地图,以及只显示南海问题
阅读量:7223 次
发布时间:2019-06-29

本文共 7623 字,大约阅读时间需要 25 分钟。

下载echarts依赖

下载依赖我想大家都会:    cnpm / npm install echarts    yar add echartstypescript项目npm install @types/echarts复制代码

引入

在main.js中引入import Echarts  form 'echarts'Vue.prototype.$echarts = Echarts复制代码

在组件中使用

mounted () {    this.drawChinaMap();},methods: {    drawChinaMap () {        let myCharts = document.getElementById('chinaMap');        let options = {            title: {                text: 'iphone销量',                subtext: '纯属虚构',                left: 'center'            },            tooltip: {                trigger: 'item'            },            legend: {                orient: 'vertical',                left: 'left',                data: ['iphone3', 'iphone4', 'iphone5']            },            visualMap: {                min: 0,                max: 2500,                left: 'left',                top: 'bottom',                text: ['高', '低'], // 文本,默认为数值文本                calculable: true            },            toolbox: {                show: true,                orient: 'vertical',                left: 'right',                top: 'center',                feature: {                    mark: {show: true},                    dataView: {show: true, readOnly: false},                    restore: {show: true},                    saveAsImage: {show: true}                }            },            series: [                {                    name: 'iphone3',                    type: 'map',                    mapType: 'china',                    roam: true,                    label: {                        normal: {                            show: false                        },                        emphasis: {                            show: true                        }                    },                    data: [                        {name: '北京', value: Math.round(Math.random() * 1000)},                        {name: '天津', value: Math.round(Math.random() * 1000)},                        {name: '上海', value: Math.round(Math.random() * 1000)},                        {name: '重庆', value: Math.round(Math.random() * 1000)},                        {name: '河北', value: Math.round(Math.random() * 1000)},                        {name: '河南', value: Math.round(Math.random() * 1000)},                        {name: '云南', value: Math.round(Math.random() * 1000)},                        {name: '辽宁', value: Math.round(Math.random() * 1000)},                        {name: '黑龙江', value: Math.round(Math.random() * 1000)},                        {name: '湖南', value: Math.round(Math.random() * 1000)},                        {name: '安徽', value: Math.round(Math.random() * 1000)},                        {name: '山东', value: Math.round(Math.random() * 1000)},                        {name: '新疆', value: Math.round(Math.random() * 1000)},                        {name: '江苏', value: Math.round(Math.random() * 1000)},                        {name: '浙江', value: Math.round(Math.random() * 1000)},                        {name: '江西', value: Math.round(Math.random() * 1000)},                        {name: '湖北', value: Math.round(Math.random() * 1000)},                        {name: '广西', value: Math.round(Math.random() * 1000)},                        {name: '甘肃', value: Math.round(Math.random() * 1000)},                        {name: '山西', value: Math.round(Math.random() * 1000)},                        {name: '内蒙古', value: Math.round(Math.random() * 1000)},                        {name: '陕西', value: Math.round(Math.random() * 1000)},                        {name: '吉林', value: Math.round(Math.random() * 1000)},                        {name: '福建', value: Math.round(Math.random() * 1000)},                        {name: '贵州', value: Math.round(Math.random() * 1000)},                        {name: '广东', value: Math.round(Math.random() * 1000)},                        {name: '青海', value: Math.round(Math.random() * 1000)},                        {name: '西藏', value: Math.round(Math.random() * 1000)},                        {name: '四川', value: Math.round(Math.random() * 1000)},                        {name: '宁夏', value: Math.round(Math.random() * 1000)},                        {name: '海南', value: Math.round(Math.random() * 1000)},                        {name: '台湾', value: Math.round(Math.random() * 1000)},                        {name: '香港', value: Math.round(Math.random() * 1000)},                        {name: '澳门', value: Math.round(Math.random() * 1000)}                    ]                },                {                    name: 'iphone4',                    type: 'map',                    mapType: 'china',                    label: {                        normal: {                            show: false                        },                        emphasis: {                            show: true                        }                    },                    data: [                        {name: '北京', value: Math.round(Math.random() * 1000)},                        {name: '天津', value: Math.round(Math.random() * 1000)},                        {name: '上海', value: Math.round(Math.random() * 1000)},                        {name: '重庆', value: Math.round(Math.random() * 1000)},                        {name: '河北', value: Math.round(Math.random() * 1000)},                        {name: '安徽', value: Math.round(Math.random() * 1000)},                        {name: '新疆', value: Math.round(Math.random() * 1000)},                        {name: '浙江', value: Math.round(Math.random() * 1000)},                        {name: '江西', value: Math.round(Math.random() * 1000)},                        {name: '山西', value: Math.round(Math.random() * 1000)},                        {name: '内蒙古', value: Math.round(Math.random() * 1000)},                        {name: '吉林', value: Math.round(Math.random() * 1000)},                        {name: '福建', value: Math.round(Math.random() * 1000)},                        {name: '广东', value: Math.round(Math.random() * 1000)},                        {name: '西藏', value: Math.round(Math.random() * 1000)},                        {name: '四川', value: Math.round(Math.random() * 1000)},                        {name: '宁夏', value: Math.round(Math.random() * 1000)},                        {name: '香港', value: Math.round(Math.random() * 1000)},                        {name: '澳门', value: Math.round(Math.random() * 1000)}                    ]                },                {                    name: 'iphone5',                    type: 'map',                    mapType: 'china',                    label: {                        normal: {                            show: false                        },                        emphasis: {                            show: true                        }                    },                    data: [                        {name: '北京', value: Math.round(Math.random() * 1000)},                        {name: '天津', value: Math.round(Math.random() * 1000)},                        {name: '上海', value: Math.round(Math.random() * 1000)},                        {name: '广东', value: Math.round(Math.random() * 1000)},                        {name: '台湾', value: Math.round(Math.random() * 1000)},                        {name: '香港', value: Math.round(Math.random() * 1000)},                        {name: '澳门', value: Math.round(Math.random() * 1000)}                    ]                }            ]        };        myCharts.setOption(optins);    }}复制代码

问题

  • 以上做法在3.x版本以上只显示南海

  • 但是画普通图表没问题

    我找了些资料看,有人说缺少china.js

    我是4.x版本

    在依赖包里发现有china.js

    于是我再次引入,问题解决

解决方案

在main.js中引入china.jsimport 'echarts/map/js/china.js';复制代码

转载于:https://juejin.im/post/5c9c94b0e51d45381b03ed70

你可能感兴趣的文章
VS2010+Oracle11+Entity Framework4.1环境搭建及常见问题(转)
查看>>
JUnit 3.8 让所有测试程序 实现 复合的测试(TestSuite)
查看>>
WPF中的MatrixTransform
查看>>
OpenGLRenderer Configuration
查看>>
静态long类型常量serialVersionUID的作用
查看>>
[android] 看博客学习hashCode()和equals()
查看>>
图解 MongoDB 地理位置索引的实现原理(转)
查看>>
js创建数组的三个方式
查看>>
云平台统计人员在线数的办法
查看>>
使用 Express 和 waterline 创建简单 Restful API
查看>>
linux sudo 命令
查看>>
MongoDB 查询总结
查看>>
struts2使用拦截器完成登陆显示用户信息操作和Struts2的国际化
查看>>
【zabbix系列】安装与加入host
查看>>
css等高布局技巧
查看>>
你绝不能错过的效率神器 —— Alfred
查看>>
009-事务管理
查看>>
泛型的继承和通配符,同时归纳集合部分的面试点
查看>>
VS 之 InstallShield Limited Edition for Visual Studio 2015 图文教程
查看>>
爬虫如何解决验证码的问题
查看>>