vue 集成 echart

本文介绍了如何使用ECharts库在JavaScript中创建一个3D散点图,并展示了如何配置视觉映射和轴指针。数据集包含一系列数值,通过设置选项实现动态颜色映射和不同维度的可视化范围。

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

<template>
  <div id="container" ref="container" style="width: 100%; height: 820px; border-color: rgb(24, 20, 50) ;background-color: rgb(16, 12, 42);"></div>
</template>

<script>
  export default {
    name: 'activeMonitorMap',
    data() {

    },
    mounted() {
      this.getEcharts()
    },
    methods: {
      getEcharts() {
        let myChart_access = this.$echarts.init(this.$refs.container)
        let symbolSize = 5
       let data = [
          [531074.073, 3485785.024, 9.971],
          [531074.277, 3485784.589, 9.829],
          [531074.481, 3485784.153, 9.688],
          [531074.684, 3485783.716, 9.549],
          [531074.885, 3485783.282, 9.407],
          [531075.088, 3485782.848, 9.262],
          [531075.293, 3485782.419, 9.115],
          [531075.503, 3485781.988, 8.969],
           [531075.718, 3485781.559, 8.826],
          [531075.937, 3485781.133, 8.687],
          [531076.16, 3485780.707, -8.551]
        ]
        myChart_access.setOption({
          trigger: 'axis',
          visualMap: [
            {
              top: 5,
              calculable: true,
              dimension: 3,
              max: 100/ 2,
              inRange: {
                    color: [
                  '#1710c0',
                  '#0b9df0',
                  '#00fea8',
                  '#00ff0d',
                  '#f5f811',
                  '#f09a09',
                  '#fe0300'
                ]
              },

                textStyle: {
                color: '#fff'
              }
            },
            {
              bottom: 10,
              calculable: true,
              dimension: 4,
              max: 100 / 2,
              inRange: {
                symbolSize: [10, 30]
              },
              textStyle: {
                color: '#fff'
              }
            }
          ],

   axisPointer: {
            type: 'cross'
          },
          grid3D: {
            axisLine: {
              lineStyle: {
                color: '#fff'
              }
            },
              axisPointer: {
              lineStyle: {
                color: '#19FFF2'
              }
            }
          },
          xAxis3D: {
            type: 'value',
            scale: true
          },
          yAxis3D: {
            type: 'value',
            scale: true
          },
          zAxis3D: {
            type: 'value',
            scale: true
          },
          dataset: {
            source: data
          },

   series: [
            {
              type: 'scatter3D',
              symbolSize: symbolSize,
              encode: {
                x: 'x',
                y: 'y',
                z: '高度',
                tooltip: [0, 1, 2, 3, 4]
              },

itemStyle: {
                // borderWidth: 1,
                // borderColor: ""
                color: '#19FFF2'
              }
            }
          ]
        })
      }
    }
  }
</script>


<style scoped>

</style>
 

### Vue3 中使用 ECharts 创建饼图 在 Vue3 项目中集成并配置 ECharts 来展示饼图,可以按照如下方式操作: #### 安装依赖库 为了能够在 Vue3 应用程序里使用 ECharts,需先安装 `echarts` 和 `vue-echarts` 组件。 ```bash npm install echarts vue-echarts ``` #### 注册全局组件 如果希望在整个应用范围内都可访问到图表,则可以在 main.js 文件内注册该插件[^1]。 ```javascript import { createApp } from 'vue'; import App from './App.vue'; // 导入 ECharts 主模块以及对应的 Vue 组件 import * as echarts from 'echarts/core'; import VChart, { THEME_KEY } from "vue-echarts"; import { PieChart } from 'echarts/charts'; // 引入柱状图图表 import { TitleComponent, TooltipComponent, LegendComponent } from 'echarts/components'; const app = createApp(App); app.use(VChart); app.config.globalProperties.$echarts = echarts; app.provide(THEME_KEY, 'light'); // 将必要的组件注入到核心对象中 echarts.use([ PieChart, TitleComponent, TooltipComponent, LegendComponent ]); app.mount('#app'); ``` #### 编写页面逻辑 接下来,在具体的视图文件 (如 Home.vue 或其他单文件组件) 内编写用于显示饼图的模板结构与脚本部分。 ```html <template> <div style="width:600px;height:400px;"> <v-chart class="chart" :option="pieOption"/> </div> </template> <script setup lang="ts"> import { ref } from 'vue'; let pieOption = ref({ title: { text: '某站点用户访问来源', subtext: '纯属虚构', left: 'center' }, tooltip: { trigger: 'item' }, legend: { orient: 'vertical', left: 'left' }, series: [ { name: '访问来源', type: 'pie', radius: '50%', data: [ { value: 1048, name: '搜索引擎' }, { value: 735, name: '直接访问' }, { value: 580, name: '邮件营销' }, { value: 484, name: '联盟广告' }, { value: 300, name: '视频广告' } ], emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }); </script> <style scoped> .chart { width: 100%; height: 100%; } </style> ``` 通过上述设置即可实现在 Vue3 环境下绘制简单的二维饼形统计图形。对于更复杂的场景比如三维效果或者其他类型的可视化需求,可以根据官方文档进一步调整选项参数来满足业务要求。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

开发软件的米良

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

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

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

打赏作者

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

抵扣说明:

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

余额充值