vue3 ECharts中引入

第一步:先安装:

npm install echarts

第二步:在组件中引入:

import * as echarts from 'echarts'; 

第三步:在自己的组见之中可以写以下代码:注:以下代码是 ECharts中的桑吉图

<template>

    <div id="echarts1" ref="container"></div>

</template>

<script setup lang="ts">

import { ref, onMounted } from "vue";

import * as echarts from 'echarts';


 

// 获取echart挂载的DOM节点

const container = ref();

onMounted(() => {

    const chart = echarts.init(container.value);

    let option = null

    var data = {

        "nodes": [

            { "name": "奥特园区" },

            { "name": "我" },

            { "name": "碧桂园" },

            { "name": "郑州西站" },

            { "name": "中原西路站" },

            { "name": "吾悦广场" }

        ],

        "links": [

            { "source": "奥特园区", "target": "我", "value": 1.1 },

            { "source": "我", "target": "郑州西站", "value": 0.8 },

            { "source": "我", "target": "碧桂园", "value": 2 },

            { "source": "我", "target": "中原西路站", "value": 1.2 },

            { "source": "吾悦广场", "target": "我", "value": 2.9 },

        ]

    }


 

    chart.setOption(option = {

        title: {

            text: '以我为中心点'

        },

        tooltip: {

            trigger: 'item',

            triggerOn: 'mousemove'

        },

        series: [

            {

                nodeGap: 100,

                nodeWidth: 50,

                type: 'sankey',

                data: data.nodes,

                links: data.links,

                focusNodeAdjacency: 'allEdges',

                itemStyle: {

                    normal: {

                        borderWidth: 1,

                        borderColor: '#aaa'

                    }

                },

                lineStyle: {

                    normal: {

                        color: 'source',

                        curveness: 0.5

                    }

                }

            }

        ]

    });


 

});

</script>

   

   

<style lang="scss" scoped>

#echarts1 {

    width: 800px;

    height: 500px;

    background: aqua;

    margin: auto;

}

</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值