使用Vue实现数据可视化大屏功能(三)-使用Echarts构建折线图功能

  在之前的文章中我们介绍了Vue中引入Echarts图表的组件,下面我们就来介绍一下如何使用这些组件构建一些基础的组件方便后续使用中的直接引用。

基础折线图的实现

第一步、创建组件文件

  在components的文件夹中创建一个BaseLine的文件夹,并且创建一个index.vue的文件。

<template>
    <div>
        <Echart :options="options" id="id" height="300px" width="500px"/>
    </div>
</template>

<script>
    import Echart from '@/common/echart'
    export default {
        data() {
            return {
                options: {}
            }
        },
        components: {
            Echart
        },
        props: {
            id: {
                type: String,
                required: true,
                default: "baseLine"
            },
            tips: {
                type: Array,
                required: true
            },
        },
        watch: {
            tips: {
                handler(newData) {
                    this.options = {
                        xAxis: {
                            type: 'category',
                            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [
                            {
                                data: newData,
                                type: 'line',
                                smooth: true
                            }

                        ]
                    }
                },
                immediate: true,
                deep: true
            }
        },
    }
</script>

<style lang="scss" scoped>

</style>

第二步、在主功能文件中引入相关组件
<template>
    <div id="index" style="width: 500px;height: 300px">
        <BaseLine :id="baseLineId" :tips="this.yData"/>
    </div>
</template>

<script>
    import BaseLine from "@/components/BaseLine"
    export default {
        data() {
            return {
                loading: true,
                baseLineId:"baseLine",
                yData:[150, 230, 224, 218, 135, 147, 260],
            }
        },
        components:{
            BaseLine
        },
        mounted(){
          this.cancelLoading();
        },
        methods:{
            cancelLoading(){
                setTimeout(() => {
                    this.loading = false;
                }, 1000);
            }
        }
    }
</script>

<style lang="scss">
</style>

第三步、启动项目查看效果

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nihui123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值