vue使用ECharts插件

1、安装

1.1、npm安装ECharts

npm install echarts --save

2、全局引入和使用

2.1、引入ECharts

在main.js中引入ECharts。

import echarts from 'echarts';
// 把 echarts 挂载到Vue实例的原型上
// 并且重命名为 $echarts
Vue.prototype.$echarts = echarts;

2.2、使用ECharts

<div id="myChart" :style="{ width: '500px', height: '500px' }"></div>
<script>
let echarts = require('echarts');
export default{
  data(){
    return{

    }
  },
  mounted() {
		this.$nextTick(() => {
			this.initChart();
		});
	},
  methods: {
    	initChart() {
			let chart = echarts.init(document.getElementById("myChart"));
			chart.setOption({
				title: {
					text: "PM 2.5 均值浓度变化情况",
					textStyle: {
						color: "#000",
					},
					x: "center",
					top: "5%",
				},
				backgroundColor: "#fff",
				tooltip: {
					trigger: "axis",
					formatter: "value:{c}<br/>时间:{b}",
				},
				// 保存图片
				toolbox: {
					top: "5%",
					right: "5%",
					iconStyle: {
						borderColor: "#1890ff",
					},
					feature: {
						saveAsImage: {
							type: "png",
							name: "PM2.5均值浓度变化情况",
						},
					},
				},
				xAxis: {
					type: "category",
					data: ["2021-09-01 10:00", "2021-09-01 11:00", "2021-09-01 12:00"],
				},
				yAxis: {
					type: "value",
					boundaryGap: false,
					name: "ug/m³",
					splitLine: {
						show: false,
					},
					// y轴不能设置值
					// data: [0, 30, 60, 90],
				},
				series: [
					{
						data: [6, 30, 60],
						type: "line",
					},
				],
			});
		},
	}

}
</script>

 3.ECharts使用文档相关链接

https://echarts.apache.org/examples/zh/index.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值