eCharts在一个页面上画多张图
以下为两张折线图为例
<template>
//第一个折线图 引用 chart
<div ref="chart" style="width: 100%; height: 400px;"></div>
//第二个折线图 引用 myChart
<div ref="myChart" style="width: 100%; height: 400px;"></div>
</template>
<script>
import * as echarts from 'echarts';
// 在组件中获取传递的参数
export default {
data() {
return {
//定义不定义都可以
myChart: null,
}
},
methods: {
//第一个折线图
drawChart() {
//初始化图表
const chart = echarts.init(this.$refs.chart);
const option = {
title: { text: '图表名字1' },
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
xAxis: { type: 'category', data:[1,2,3,4,5,6]},
yAxis: { type: 'value' },
series: [{name: '折线图线的名字', type: 'line', smooth: true, step: 'end', data: [1,2,3,4,5,6] ,
itemStyle: {
normal: {
color: '#B22222', //改变折线点的颜色
lineStyle: {
color: '#B22222' //改变折线颜色
}
}
}}],
};
//设置图表属性
chart.setOption(option);
},
//第二个折线图
seatsChart() {
//初始化图表
const myChart = echarts.init(this.$refs.myChart);
const option = {
title: { text: '图表名字2' },
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
xAxis: { type: 'category', data: [1,2,3,4,5,6]},
yAxis: { type: 'value' },
series: [{ name: '折线图线的名字',type: 'line', smooth: true, step: 'end', data: [1,2,3,4,5,6],
itemStyle: {
normal: {
color: '#008000', //改变折线点的颜色
lineStyle: {
color: '#008000' //改变折线颜色
}
}
}
}],
};
//设置图表属性
myChart.setOption(option);
},
},
mounted() {
this.drawChart();
this.seatsChart();
});
},
}
</script>
<style></style>