当前位置: 首页 > news >正文

Echarts立体柱状图

1.npm安装echarts

npm install echarts --save

2.全局引入echarts

main.js文件中:

import * as echarts from 'echarts';
Vue.prototype.$echarts =  echarts

3.新建组件vue文件   --   echartsPage.vue

<template>
    <div ref="echartsCanvas" class="echarts-style"></div>
</template>

<script>
    export default {
        name: 'Search',
        data() {
            return {
                seriesData:[],
                xAxisData:[],
            };
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {
                this.seriesData = [33,14,14,8,8,7,6,4,4,3,2,1,10]
                this.xAxisData =  ['影视', '高端装备', '计算机', '总集成', '3d打印','影1视', '高端1装备', '计算1机', '总集1成', '3d打1印','计算机1', '总集成1', '13d打印']
                const offsetX = 20
                const offsetY = 10
                // 绘制左侧面
                const CubeLeft = this.$echarts.graphic.extendShape({
                    shape: {
                        x: 0,
                        y: 0
                    },
                    buildPath: function (ctx, shape) {
                        // 会canvas的应该都能看得懂,shape是从custom传入的
                        const xAxisPoint = shape.xAxisPoint
                        const c0 = [shape.x, shape.y]  //右下
                        const c1 = [shape.x - offsetX-offsetY, shape.y ]  //左上
                        const c2 = [xAxisPoint[0] - offsetX-offsetY, xAxisPoint[1] ]  //左下
                        const c3 = [xAxisPoint[0], xAxisPoint[1]]  //右上
                        ctx.moveTo(c0[0], c0[1]).lineTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).closePath()
                    }
                })
                // 绘制右侧面
                const CubeRight = this.$echarts.graphic.extendShape({
                    shape: {
                        x: 0,
                        y: 0
                    },
                    buildPath: function (ctx, shape) {
                        const xAxisPoint = shape.xAxisPoint
                        const c1 = [shape.x, shape.y]
                        const c2 = [xAxisPoint[0], xAxisPoint[1]]
                        const c3 = [xAxisPoint[0] + offsetX- offsetY, xAxisPoint[1] - offsetY- offsetY+3]
                        const c4 = [shape.x + offsetX - offsetY, shape.y - offsetY- offsetY+3]
                        ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath()
                    }
                })
                // 绘制顶面
                const CubeTop = this.$echarts.graphic.extendShape({
                    shape: {
                        x: 0,
                        y: 0
                    },
                    buildPath: function (ctx, shape) {
                        const c1 = [shape.x, shape.y]
                        const c2 = [shape.x + offsetX- offsetY, shape.y - offsetY- offsetY+3] // 右点
                        const c3 = [shape.x- offsetY- offsetY, shape.y - offsetX+3]
                        const c4 =[shape.x- offsetX- offsetY, shape.y]
                        ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath()
                    }
                })
                // 注册三个面图形
                this.$echarts.graphic.registerShape('CubeLeft', CubeLeft)
                this.$echarts.graphic.registerShape('CubeRight', CubeRight)
                this.$echarts.graphic.registerShape('CubeTop', CubeTop)

                const option = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    grid: {
                        left: '5%',
                        right: '5%',
                        top: '10%',
                        bottom: '10%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        data: this.xAxisData ,
                        axisLine: {
                            show: true,
                            lineStyle: {
                                width: 1,
                                color: '#000000'
                            }
                        },
                        axisTick: {
                            show: false
                        },
                        axisLabel: {
                            fontSize: 10
                        }
                    },
                    yAxis: {
                        type: 'value',
                        axisLine: {
                            show: false,
                            lineStyle: {
                                width: 2,
                                color: '#000000'
                            }
                        },
                        splitLine: {
                            show: true,
                            lineStyle: {
                                color: '#2A353F',
                                type: 'dashed'
                            }
                        },
                        axisTick: {
                            show: false
                        },
                        axisLabel: {
                            fontSize: 12
                        }
                    },
                    dataZoom: [{
                        type: 'slider',
                        show: false,
                        realtime: true,
                        startValue: 0,
                        endValue: 12, // 初始显示index0-30的数据,可根据你的数据量设置
                        filterMode: 'none',
                    },],
                    series: [
                        {
                            type: 'custom',
                            renderItem: (params, api) => {
                                const location = api.coord([api.value(0), api.value(1)])
                                return {
                                    type: 'group',
                                    x: 0,
                                    children: [
                                        {
                                            type: 'CubeLeft',
                                            shape: {
                                                api,
                                                xValue: api.value(0),
                                                yValue: api.value(1),
                                                x: location[0],
                                                y: location[1],
                                                xAxisPoint: api.coord([api.value(0), 0])
                                            },
                                            style: {
                                                fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                                    {
                                                        offset: 0,
                                                        color: '#8DC21F'
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: '#00A1A3'
                                                    }
                                                ])
                                            }
                                        },
                                        {
                                            type: 'CubeRight',
                                            shape: {
                                                api,
                                                xValue: api.value(0),
                                                yValue: api.value(1),
                                                x: location[0],
                                                y: location[1],
                                                xAxisPoint: api.coord([api.value(0), 0])
                                            },
                                            style: {
                                                fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                                    {
                                                        offset: 0,
                                                        color: '#70A600'
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: '#027E80'
                                                    }
                                                ])
                                            }
                                        },
                                        {
                                            type: 'CubeTop',
                                            shape: {
                                                api,
                                                xValue: api.value(0),
                                                yValue: api.value(1),
                                                x: location[0],
                                                y: location[1],
                                                xAxisPoint: api.coord([api.value(0), 0])
                                            },
                                            style: {
                                                fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                                    {
                                                        offset: 0,
                                                        color: '#8DC21F'
                                                    },
                                                    {
                                                        offset: 1,
                                                        color: '#70A600'
                                                    }
                                                ])
                                            }
                                        }
                                    ]
                                }
                            },
                            data: this.seriesData
                        }
                    ]
                }

                let  myChart = this.$echarts.init(this.$refs.echartsCanvas);

                myChart.setOption(option);
            }
        }
    }
</script>

<style lang="less" scoped>
  .echarts-style{
      width: 1000px;
      height: 400px;
  }
</style>

相关文章:

  • SpringBoot定时任务@Scheduled注解详解
  • Gen-LaneNet论文精读总结
  • Spring Cloud Alibaba全家桶——微服务网关Gateway组件
  • 基于微信PC端小程序抓包方法
  • SQL Server 实现邮件发送功能(配置步骤及存储过程源码)
  • 刘禹锡最经典诗文10首,每一首都是千古名作,读懂受益一生
  • mybatisplus快速实现动态数据源切换
  • Vue-条件渲染的基本使用(v-if,v-show,v-else相关指令使用)
  • PMP项目管理认证第一节(备考阶段准备)
  • 【数据结构】TopK,堆排序, --堆的初始化与应用
  • 自然语言处理: 知识图谱的十年
  • 关于加解密、加签、验签等
  • 分布式事务问题
  • 终于解决了悬疑好多年的低版本CAD VBA不能在高版本CAD使用的问题
  • SpringBoot 项目的创建与启动
  • 深入了解以太坊
  • [译] React v16.8: 含有Hooks的版本
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • 〔开发系列〕一次关于小程序开发的深度总结
  • 2017 年终总结 —— 在路上
  • 2017 前端面试准备 - 收藏集 - 掘金
  • Docker下部署自己的LNMP工作环境
  • E-HPC支持多队列管理和自动伸缩
  • Java方法详解
  • Joomla 2.x, 3.x useful code cheatsheet
  • js
  • Linux下的乱码问题
  • Node项目之评分系统(二)- 数据库设计
  • PaddlePaddle-GitHub的正确打开姿势
  • Python利用正则抓取网页内容保存到本地
  • Vue.js源码(2):初探List Rendering
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • Web标准制定过程
  • 关于使用markdown的方法(引自CSDN教程)
  • 前端每日实战:61# 视频演示如何用纯 CSS 创作一只咖啡壶
  • 如何使用 JavaScript 解析 URL
  • 问:在指定的JSON数据中(最外层是数组)根据指定条件拿到匹配到的结果
  • 写给高年级小学生看的《Bash 指南》
  • “十年磨一剑”--有赞的HBase平台实践和应用之路 ...
  • 2017年360最后一道编程题
  • k8s使用glusterfs实现动态持久化存储
  • raise 与 raise ... from 的区别
  • ​LeetCode解法汇总1410. HTML 实体解析器
  • ​软考-高级-系统架构设计师教程(清华第2版)【第1章-绪论-思维导图】​
  • #预处理和函数的对比以及条件编译
  • (pytorch进阶之路)CLIP模型 实现图像多模态检索任务
  • (超详细)2-YOLOV5改进-添加SimAM注意力机制
  • (分布式缓存)Redis分片集群
  • (附源码)php新闻发布平台 毕业设计 141646
  • (附源码)ssm基于微信小程序的疫苗管理系统 毕业设计 092354
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (附源码)ssm经济信息门户网站 毕业设计 141634
  • (附源码)计算机毕业设计SSM疫情社区管理系统
  • (亲测有效)解决windows11无法使用1500000波特率的问题
  • (三)mysql_MYSQL(三)