eCharts在一个页面上画多张图

文章详细描述了如何在Vue组件中利用eCharts库在同一页面上创建并展示两张独立的折线图,包括图表的初始化、数据配置和样式定制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值