VUE3 ECharts 实现阶梯瀑布图(附源码和效果)

文章介绍了如何在Vue.js应用中利用ECharts库创建一个瀑布图,展示数据的正负变化,包括初始化图表、配置选项和数据处理过程。
摘要由CSDN通过智能技术生成
<template>
  <div id="main" class="echart-style">
  </div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
import { onMounted, ref } from 'vue';
let myChart = ref()
let option = ref({})
let data = ref([900, 345, 393, -108, -154, 135, 178, 286, -119, -361, -203]);
let help: any = [];
let positive: any = [];
let negative: any = [];
for (let i = 0, sum = 0; i < data.value.length; ++i) {
  if (data.value[i] >= 0) {
    positive.push(data.value[i]);
    negative.push('-');
  } else {
    positive.push('-');
    negative.push(-data.value[i]);
  }

  if (i === 0) {
    help.push(0);
  } else {
    sum += data.value[i - 1];
    if (data.value[i] < 0) {
      help.push(sum + data.value[i]);
    } else {
      help.push(sum);
    }
  }
}
onMounted(() => {
  init()
})
const init = () => {
  // 基于准备好的dom,初始化echarts实例
  myChart.value = echarts.init(document.getElementById('main'));
  // 绘制图表
  option.value = {
    title: {
      text: 'Waterfall'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      splitLine: { show: false },
      data: (function () {
        var list = [];
        for (var i = 1; i <= 11; i++) {
          list.push('Oct/' + i);
        }
        return list;
      })()
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        type: 'bar',
        stack: 'all',
        itemStyle: {
          normal: {
            barBorderColor: 'rgba(0,0,0,0)',
            color: 'rgba(0,0,0,0)'
          },
          emphasis: {
            barBorderColor: 'rgba(0,0,0,0)',
            color: 'rgba(0,0,0,0)'
          }
        },
        data: help
      },
      {
        name: 'positive',
        type: 'bar',
        stack: 'all',
        data: positive
      },
      {
        name: 'negative',
        type: 'bar',
        stack: 'all',
        data: negative,
        itemStyle: {
          color: '#f33'
        }
      }
    ]
  };
  myChart.value.setOption(option.value)
};
</script>
<style scoped>
.echart-style {
  width: 1000px;
  height: 900px;
  background: skyblue;
}
</style>

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用Vue.jsecharts实现3D世界地,您需要遵循以下步骤: 1. 安装echartsecharts-gl 使用npm或yarn安装echartsecharts-gl。 ``` npm install echarts echarts-gl --save ``` 2. 创建Vue.js组件 创建一个Vue.js组件,并在其中引入echarts。 ``` <template> <div ref="chart" style="width:100%;height:600px;"></div> </template> <script> import echarts from 'echarts'; import 'echarts-gl'; export default { name: 'WorldMap', data() { return { chart: null }; }, mounted() { this.chart = echarts.init(this.$refs.chart); this.chart.setOption(this.getOption()); }, methods: { getOption() { return { globe: { baseTexture: '/static/img/map/world.topo.bathy.200401.jpg', heightTexture: '/static/img/map/world.topo.bathy.200401.jpg', displacementScale: 0.1, shading: 'lambert', environment: '/static/img/map/starfield.jpg', light: { ambient: { intensity: 0.1 }, main: { intensity: 1.5 } }, viewControl: { autoRotate: true } }, series: [{ type: 'lines3D', coordinateSystem: 'globe', data: this.getLinesData(), lineStyle: { width: 1, color: '#00ffff' } }] }; }, getLinesData() { // 根据需要自己获取数据 return [ // 数据格式:[[起点经度, 起点纬度], [终点经度, 终点纬度]] [[-73.985664, 40.748817], [139.710164, 35.706962]], [[-118.243685, 34.052312], [139.710164, 35.706962]], [[-0.126608, 51.507227], [139.710164, 35.706962]], [[-74.005941, 40.712784], [139.710164, 35.706962]], [[-122.419416, 37.774929], [139.710164, 35.706962]], [[-87.629798, 41.878114], [139.710164, 35.706962]], [[-77.036871, 38.907192], [139.710164, 35.706962]], [[-77.208946, 38.882334], [139.710164, 35.706962]], [[-118.4911912, 34.0194543], [139.710164, 35.706962]], [[-118.3273455, 34.0830908], [139.710164, 35.706962]], [[-122.4194155, 37.7749295], [139.710164, 35.706962]], [[-0.126608, 51.507227], [139.710164, 35.706962]], [[-73.9866136, 40.7292535], [139.710164, 35.706962]], [[-118.243685, 34.052312], [139.710164, 35.706962]], [[-77.036871, 38.907192], [139.710164, 35.706962]], [[-87.6297982, 41.8781136], [139.710164, 35.706962]], [[-77.208946, 38.882334], [139.710164, 35.706962]], [[-80.1917902, 25.7616798], [139.710164, 35.706962]], [[-118.4911912, 34.0194543], [139.710164, 35.706962]], [[-118.3273455, 34.0830908], [139.710164, 35.706962]], [[-74.0059413, 40.7127837], [139.710164, 35.706962]], [[-73.9856644, 40.7488168], [139.710164, 35.706962]], [[-122.4194155, 37.7749295], [139.710164, 35.706962]], [[-122.419416, 37.774929], [139.710164, 35.706962]], [[-74.005941, 40.712784], [139.710164, 35.706962]], [[-118.243685, 34.052312], [139.710164, 35.706962]], [[-87.629798, 41.878114], [139.710164, 35.706962]], [[-77.036871, 38.907192], [139.710164, 35.706962]], [[-77.208946, 38.882334], [139.710164, 35.706962]], [[-118.4911912, 34.0194543], [139.710164, 35.706962]], [[-118.3273455, 34.0830908], [139.710164, 35.706962]], [[-0.126608, 51.507227], [139.710164, 35.706962]], [[-73.9866136, 40.7292535], [139.710164, 35.706962]], [[-122.4194155, 37.7749295], [139.710164, 35.706962]], [[-74.0059413, 40.7127837], [139.710164, 35.706962]], [[-73.9856644, 40.7488168], [139.710164, 35.706962]], [[-118.243685, 34.052312], [139.710164, 35.706962]], [[-87.6297982, 41.8781136], [139.710164, 35.706962]], [[-77.036871, 38.907192], [139.710164, 35.706962]], [[-77.208946, 38.882334], [139.710164, 35.706962]], [[-118.4911912, 34.0194543], [139.710164, 35.706962]], [[-118.3273455, 34.0830908], [139.710164, 35.706962]], [[-122.419416, 37.774929], [139.710164, 35.706962]], [[-0.126608, 51.507227], [139.710164, 35.706962]], [[-73.9866136, 40.7292535], [139.710164, 35.706962]], [[-118.243685, 34.052312], [139.710164, 35.706962]], [[-74.005941, 40.712784], [139.710164, 35.706962]], [[-73.985664, 40.748817], [139.710164, 35.706962]], [[-87.629798, 41.878114], [139.710164, 35.706962]], [[-77.036871, 38.907192], [139.710164, 35.706962]], [[-77.208946, 38.882334], [139.710164, 35.706962]], [[-80.1917902, 25.7616798], [139.710164, 35.706962]], [[-118.4911912, 34.0194543], [139.710164, 35.706962]], [[-118.3273455, 34.0830908], [139.710164, 35.706962]], [[-122.4194155, 37.7749295], [139.710164, 35.706962]] ]; } } }; </script> ``` 3. 通过组件显示地Vue.js应用程序中使用地组件。 ``` <template> <div> <WorldMap /> </div> </template> <script> import WorldMap from './WorldMap.vue'; export default { components: { WorldMap } }; </script> ``` 这样,您就可以在Vue.js应用程序中使用echarts来显示3D世界地了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值