【记录45】【案例】echarts 柱状图3D效果

环境

echarts@4.1.0
在这里插入图片描述

<template>
<!-- 商场各楼层统计 -->
    <div id="threethree"></div>
</template>

<script>
import * as echarts from "echarts"
export default {
    name:"",
    components:{},
    data(){
        return {

        }
    },
    methods:{
        getdata(){
            var myCharts = echarts.init(document.getElementById('threethree'))
            // mock 数据
            const dataArr = {
                xdata: ['商场一楼', '商场二楼', '商场三年楼', '商场四楼', '商场五楼', '商场负一楼',],
                result: [
                    { name: 'Ⅰ级', data: [0, 0, 0, 0, 0, 0, ] },
                    { name: 'Ⅱ级', data: [1, 0, 1, 0, 1, 0, ] },
                    { name: 'Ⅲ级', data: [1, 4, 0, 1, 0, 2, ] },
                    // { name: 'Ⅳ级', data: [5, 3, 6, 4, 2, 1, 4, 4, 10] },
                ]
            }
            // 头部菱形
            const diamondData = dataArr.result.reduce((pre, cur, index) => {
                pre[index] = cur.data.map((el, id) => el + ( pre[index - 1] ? pre[index - 1][id] : 0))
                return pre
            }, [])

            // color
            const color = [
                [{ offset: 0, color: "#dc0707", }, { offset: 0.5, color: "#dc0707", }, { offset: 0.5, color: "#af0808", }, { offset: 1, color: "#af0808", }],
                [{ offset: 0, color: "#f67c20", }, { offset: 0.5, color: "#f67c20", }, { offset: 0.5, color: "#cc681e", }, { offset: 1, color: "#cc681e", }],
                [{ offset: 0, color: "#efff37", }, { offset: 0.5, color: "#efff37", }, { offset: 0.5, color: "#d5e700", }, { offset: 1, color: "#d5e700", }],
                [{ offset: 0, color: "#6495ED", }, { offset: 0.5, color: "#6495ED", }, { offset: 0.5, color: "#6495ED", }, { offset: 1, color: "#4169E1", }],
                [{ offset: 0, color: "#46c9ff", }, { offset: 0.5, color: "#46c9ff", }, { offset: 0.5, color: "#00b4ff", }, { offset: 1, color: "#00b4ff", }],
                [{ offset: 0, color: "#54a0ff", }, { offset: 0.5, color: "#54a0ff", }, { offset: 0.5, color: "#1f83ff", }, { offset: 1, color: "#1f83ff", }],
            ]

            // series
            let series = dataArr.result.reduce((p, c, i, array) => {
                p.push({
                    z: i + 1,
                    stack: '总量',
                    type: 'bar',
                    name: c.name,
                    barGap: '-100%',
                    barWidth: 30,
                    data: c.data,
                    itemStyle:{ color: { type: 'linear', x: 0, x2: 1, y: 0, y2: 0, colorStops: color[i] } },
                },{
                    z: i + 10,
                    type: 'pictorialBar',
                    symbolPosition: 'end',
                    symbol: 'diamond',
                    symbolOffset: [0, '-50%'],
                    symbolSize: [30, 10],
                    data: diamondData[i],
                    itemStyle: { color: { type: 'linear', x: 0, x2: 1, y: 0, y2: 0, colorStops: color[i] } },
                    tooltip: { show: false },
                })

                // 是否最后一个了?
                if (p.length  === (array.length) * 2) {
                    p.push({
                        z: array.length * 2,
                        type: "pictorialBar",
                        symbolPosition: "start",
                        data: dataArr.result[0].data,
                        symbol: "diamond",
                        symbolOffset: ["0%", "50%"],
                        symbolSize: [30, 10],
                        itemStyle: { color: { type: 'linear', x: 0, x2: 1, y: 0, y2: 0, colorStops: color[0]} },
                        tooltip: { show: false },
                    })
                    return p
                }

                return p
            }, [])

            // tooltip
            const tooltip = { trigger: "axis" }

            // legend
            const legend = {
                data: dataArr.result.map(item => item.name),
                textStyle: { fontSize: 14, color: '#fff'},
                itemWidth: 25,
                itemHeight: 15,
                itemGap: 15,
                top: '5%',
            }
            // grid
            const grid = { top: '18%', left: '10%', right: '3%', bottom: '20%'}

            // xAxis
            const xAxis = { 
                axisTick: { show: false },
                axisLine: { lineStyle: { color: 'rgba(255,255,255, .2)' } },
                axisLabel: { textStyle: { fontSize: 12, color: '#fff'  },interval:0,rotate:20, },
                data: dataArr.xdata
            }

            // yAxis
            const yAxis = [{ 
                splitLine: { lineStyle: { color: 'rgba(255,255,255, .05)' } },
                axisLine: { show: false, },
                axisLabel: { textStyle: { fontSize: 16, color: '#fff' } }
            }]

            const dataZoom = [{ // 缩放条
                    type: 'inside',
                    start: 10,
                    end: 90
                    }, {
                    start: 30,
                    end: 80
                }]

            // 渲染
            let option = { tooltip, xAxis, yAxis, series, grid, legend, dataZoom, backgroundColor:'' }
            myCharts.setOption(option)
        }
    },
    mounted(){
        this.getdata()
    }
}
</script>
<style>
    #threethree { width: 100%; height: 27vh; }
</style>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值