在vue项目中使用echarts制作3D效果柱状图

在vue项目中使用echarts制作3D效果柱状图

1、第一步安装echarts组件。
npm install echarts
2、第二步安装好echarts后,安装echarts3d图形组件echarts-gl
npm install echarts-gl

如果package.json文件里面也可以找到这个配置,则安装成功
在这里插入图片描述
3.第三步在需要使用Echarts页面的script中附上以下代码
在这里插入图片描述

import * as echarts from 'echarts';
import 'echarts-gl';
require('echarts/lib/chart/bar.js');
require('echarts/lib/component/title.js');
require('echarts/lib/component/tooltip.js');

实例上代码!

<template>
  <div class="ChartAnalysis">
    <!-- 内容 -->
    <div id="main"></div>
  </div>
</template>

<script>

import * as echarts from 'echarts';
import 'echarts-gl';
require('echarts/lib/chart/bar.js');
require('echarts/lib/component/tooltip.js');
require('echarts/lib/component/title.js');

export default {
  name: "WaterMeter",
  mounted() {
    this.chartthreenD();
  },
  methods: {
    chartthreenD(){
     var myChart = echarts.init(document.getElementById('main'));
      var option = {
          title: {
                  text: '3D堆叠柱状图',
                  x: 'center'
              },
            color: ['#5470c6','#7ed3f4','#ffdc60','#9fe080','#0fa4ff','#1e1e1e','#25a0da','#4575b4','#313695','#4575b4','#313695'],
            tooltip: {},
            xAxis3D: {
                type: 'category',
                data: ['1111', '2222','3333', '4444','5555', '6666'],
                axisLine:{
                    lineStyle:{
                        color:'black',
                        width:2
                    }
                },
            },
            yAxis3D: {
                type: 'category',
                data: [''],
                axisLine:{
                    lineStyle:{
                      width:1,
                      color:'black',
                    }
                },
            },
            zAxis3D: {
                type: 'value',
                axisLine:{
                    lineStyle:{
                        color:'black',
                        width:1
                    }
                },
            },
            grid3D: {
                boxWidth: 200,
                boxDepth: 20,
                // splitLine:{//是否显示坐标轴轴线
                //   show:false
                // },
                axisPointer: {
                    show: false
                },
                light: {
                    main: {
                        intensity: 1
                    },
                    ambient: {
                        intensity: 0.4
                    }
                },
                viewControl: {//可以控制整个柱状图场景旋转平移等,自行代数数据试试
                    alpha: 0, 
                    beta: 0,
                    minAlpha: 0,//x轴旋转
                    maxAlpha: 0,
                    minBeta: 0,//y轴旋转
                    maxBeta: 0
                }
            },
            series: [{
                type: 'bar3D',
                
                name:'数据',
                barSize: 10,//柱子大小
                data: [
                    [0, 0, 5],
                    [2, 0, 4],
                    [4, 0, 6],
                ],
                stack: 'stack',
                shading: 'lambert',
                emphasis: {
                    label: {
                        show: true
                    }
                }
            }, {
                type: 'bar3D',
                name:'数据',
                barSize: 10,
                data: [
                    [1, 0, 10],
                    [3, 0, 6],
                    [5, 0, 12],
                ],
                // stack: 'stack',
                shading: 'lambert',
                emphasis: {
                    label: {
                        show: true
                    }
                }
            }]
        };
        myChart.setOption(option);
    }
  },
};
</script>

<style scoped>
#main{
  width: 100%;
  height: 100%;
}
</style>

在这里插入图片描述

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值