我是靠谱客的博主 故意身影,最近开发中收集的这篇文章主要介绍vue+echarts 实现(显示)中国地图 Component series.XXX not exists,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
1. 安装较低版本 npm install echarts@4.9.0
千万注意 。echarts 的图形组件是按需加载,不是 import echarts from "echarts" 就可以。
加载echarts 相关模块(提示缺什么就加载什么组件即可)
main.js
import echarts from "echarts/lib/echarts";
import 'echarts/lib/chart/map'
import 'echarts/lib/chart/scatter'
// import 'echarts/map/js/china'
import china from 'echarts/map/json/china.json'
echarts.registerMap('china', china)
Vue.prototype.$echarts = echarts
2.页面demo
<template>
<div class="echarts">
<div id="myChartChina" :style="{ width: '100%', height: '500px' }"></div>
</div>
</template>
<script>
export default {
name: "echarts",
props: ["userJson"],
data() {
return {
chart: null,
};
},
mounted() {
this.drawLine();
},
methods: {
drawLine() {
// 基于准备好的dom,初始化echarts实例
var myChartContainer = document.getElementById("myChartChina");
var resizeMyChartContainer = function () {
myChartContainer.style.width = document.body.offsetWidth / 2 + "px"; //页面一半的大小
};
resizeMyChartContainer();
var myChartChina = this.$echarts.init(myChartContainer);
function randomData() {
return Math.round(Math.random() * 500);
}
// 绘制图表
var optionMap = {
tooltip: {},
legend: {
orient: "vertical",
left: "left",
data: [""],
},
visualMap: {
min: 0,
max: 1500,
left: "10%",
top: "bottom",
text: ["高", "低"],
calculable: true,
color: ["#0b50b9", "#c3e2f4"],
},
selectedMode: "single",
series: [
{
name: "",
type: "map",
mapType: "china",
itemStyle: {
normal: {
borderColor: "rgba(0, 0, 0, 0.2)",
},
emphasis: {
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 20,
borderWidth: 0,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
},
showLegendSymbol: true,
label: {
normal: {
show: true,
},
emphasis: {
show: true,
},
},
data: [
{ name: "北京", value: randomData() },
{ name: "天津", value: randomData() },
{ name: "上海", value: randomData() },
{ name: "重庆", value: randomData() },
{ name: "河北", value: randomData() },
{ name: "河南", value: randomData() },
{ name: "云南", value: randomData() },
{ name: "辽宁", value: randomData() },
{ name: "黑龙江", value: randomData() },
{ name: "湖南", value: randomData() },
{ name: "安徽", value: randomData() },
{ name: "山东", value: randomData() },
{ name: "新疆", value: randomData() },
{ name: "江苏", value: randomData() },
{ name: "浙江", value: randomData() },
{ name: "江西", value: randomData() },
{ name: "湖北", value: randomData() },
{ name: "广西", value: randomData() },
{ name: "甘肃", value: randomData() },
{ name: "山西", value: randomData() },
{ name: "内蒙古", value: randomData() },
{ name: "陕西", value: randomData() },
{ name: "吉林", value: randomData() },
{ name: "福建", value: randomData() },
{ name: "贵州", value: randomData() },
{ name: "广东", value: randomData() },
{ name: "青海", value: randomData() },
{ name: "西藏", value: randomData() },
{ name: "四川", value: randomData() },
{ name: "宁夏", value: randomData() },
{ name: "海南", value: randomData() },
{ name: "台湾", value: randomData() },
{ name: "香港", value: randomData() },
{ name: "澳门", value: randomData() },
],
},
],
};
myChartChina.setOption(optionMap);
window.onresize = function () {
resizeMyChartContainer();
myChartChina.resize();
};
},
},
};
</script>
最后
以上就是故意身影为你收集整理的vue+echarts 实现(显示)中国地图 Component series.XXX not exists的全部内容,希望文章能够帮你解决vue+echarts 实现(显示)中国地图 Component series.XXX not exists所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复