1、版本问题 一直错误大概率版本问题
卸载:
npm uninstall echarts
安装指定版本:
npm install echarts@4.9.0 --save
4.9版本下有地图,5.0版本以上失去这个功能,想要别的版本把@后的版本号改掉就行。
2、快速上手步骤
(1)需要的组件中引入
import echarts from "echarts"; (import "echarts/map/js/china";)
(2)设置配置项 例如:
const option = {
title: {
text: "category",
link: "https://www.baidu.com",
},
series: [
{
name: "确诊人数",
type: "map",
map: "china",
},
],
};
3、设置一个有width height的盒子
mounted() {
/*ECharts图表*/
// 初始化
this.myChart = echarts.init(this.$refs.main);
// 配置项
this.myChart.setOption(option);
},
完整代码:
<template>
<div ref="main" :style="{ width: '900px', height: '500px' }"></div>
</template>
<script>
import echarts from "echarts";
import "echarts/map/js/china";
const option = {
title: {
text: "category",
link: "https://www.baidu.com",
},
series: [
{
name: "确诊人数",
type: "map",
map: "china",
},
],
};
export default {
name: "Home",
mounted() {
/*ECharts图表*/
// 初始化
this.myChart = echarts.init(this.$refs.main);
// 配置项
this.myChart.setOption(option);
},
};
</script>
<style scoped>
</style>