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

做盗版漫画网站深圳网络优化推广公司

做盗版漫画网站,深圳网络优化推广公司,贵州建设考试网站,创意产品设计网站推荐echarts如何画立体柱状图 一、创建盒子1、创建盒子2、初始化盒子(先绘制一个基本的二维柱状图的样式)1、创建一个初始化图表的方法2、在mounted中调用这个方法3、在方法中写options和绘制图形 二、画图前知识1、坐标2、柱状图图解分析 三、构建方法1、创…

echarts如何画立体柱状图

  • 一、创建盒子
    • 1、创建盒子
    • 2、初始化盒子(先绘制一个基本的二维柱状图的样式)
      • 1、创建一个初始化图表的方法
      • 2、在mounted中调用这个方法
      • 3、在方法中写options和绘制图形
  • 二、画图前知识
    • 1、坐标
    • 2、柱状图图解分析
  • 三、构建方法
    • 1、创建一个用来绘制形状的方法,drawShape
    • 2、完善drawShape方法
      • 1、完善 leftShape 形状逻辑:
      • 2、完善 rightShape 形状逻辑
      • 3、完善 topShape 形状逻辑
    • 3、修改initChart方法
      • 1、修改series
  • 四、效果图

一、创建盒子

1、创建盒子

这是图形盒子和样式。

<template><div class="MonitoringSensor"><div id="main"></div></div>
</template>
<style scoped>
.MonitoringSensor {width: 500px;height: 500px;margin: 0 auto;background: rgb(24, 80, 169)
}#main {height: 100%;width: 100%;
}
</style>

这一步做完页面中间会有一个蓝色的盒子,如下
在这里插入图片描述

2、初始化盒子(先绘制一个基本的二维柱状图的样式)

1、创建一个初始化图表的方法

  methods:{initChart () {}}

2、在mounted中调用这个方法

  mounted () {this.initChart()},

3、在方法中写options和绘制图形

注意:记得导入echarts,否则无法构建图表。

import * as echarts from 'echarts'
data () {return {chart: null}},
initChart () {this.chart = echarts.init(document.getElementById('main'));let options = null;options = {xAxis: {type: "category",data: ["苹果", "梨子", "香蕉"],axisLabel: {color: "#fff",},},yAxis: {type: "value",max: 200,axisLabel: {color: "#fff",},splitLine: {lineStyle: {color: "#222",},},},tooltip: {trigger: "axis",},series: [{type: "bar",data: [100, 50, 20],barWidth: 30,},],};options && this.chart.setOption(options);},

到这个时候,能看到页面有一个基本的柱状图的样子了,如下图:
在这里插入图片描述

二、画图前知识

1、坐标

echarts中的坐标是跟着图例盒子大小来的,比如我这个main盒子是设置了500*500大小
在这里插入图片描述
那么坐标是怎么看的,那么左上角的话就是(0,0),右上角就是(500,0),左下角就是(0,500),右下角就是(500,500),相当于右边是X轴正轴,往下看是Y轴正轴
在这里插入图片描述

2、柱状图图解分析

图1:
在这里插入图片描述

图2:
在这里插入图片描述

根据图1和坐标知识可知:
在这里插入图片描述

左侧面的坐标信息为:
P1:【基础X轴坐标点-侧面宽度,顶部Y轴坐标点-斜角高度】
P2:【基础X轴坐标点-侧面宽度,底部Y轴坐标点】
P3:【基础X轴坐标点,底部Y轴坐标点】
P4:【基础X轴坐标点,顶部Y轴坐标点】

根据图2和坐标知识可得:
在这里插入图片描述
右侧面的坐标信息为
P1:【基础X轴坐标点,顶部Y轴坐标点】
P2:【基础X轴坐标点,底部Y轴坐标点】
P3:【基础X轴坐标点 +侧面宽度 ,底部Y轴坐标点】
P4:【基础X轴坐标点 +侧面宽度,顶部Y轴坐标点 - 斜角高度】

根据图2和坐标知识可得:
在这里插入图片描述

顶面的坐标信息为
P1:【基础X轴坐标点,顶部Y轴坐标点】
P2:【基础X轴坐标点+侧面宽度,顶部Y轴坐标点- 斜角高度】
P3:【基础X轴坐标点 ,顶部Y轴坐标点- 斜角高度*2】
P4:【基础X轴坐标点 -侧面宽度,顶部Y轴坐标点 - 斜角高度】

三、构建方法

1、创建一个用来绘制形状的方法,drawShape

这个方法里面先创建三个形状的空壳子,并注册,如下图,并且注册完成以后在这个方法里面调用构建图表的方法initChart,在初始化页面的时候就不用调用initChart方法了

 mounted () {this.drawShape()},
 drawShape () {const leftShape = echarts.graphic.extendShape({buildPath (ctx, shape) { },});const rightShape = echarts.graphic.extendShape({buildPath (ctx, shape) { },});const topShape = echarts.graphic.extendShape({buildPath (ctx, shape) { },});echarts.graphic.registerShape("leftShape", leftShape);echarts.graphic.registerShape("rightShape", rightShape);echarts.graphic.registerShape("topShape", topShape);this.initChart()},

到这一步会报错,因为方法中的ctx和shape没引用,是正常现象,到后面这两个参数使用了以后就不报错了。报错如下图所示,暂时可以不用管
在这里插入图片描述

2、完善drawShape方法

1、完善 leftShape 形状逻辑:

 const leftShape = echarts.graphic.extendShape({buildPath (ctx, shape) {const { topBasicsYAxis, bottomYAxis, basicsXAxis } = shape;// 侧面宽度const WIDTH = 15;// 斜角高度const OBLIQUE_ANGLE_HEIGHT = 3.6;const p1 = [basicsXAxis - WIDTH, topBasicsYAxis - OBLIQUE_ANGLE_HEIGHT];const p2 = [basicsXAxis - WIDTH, bottomYAxis];const p3 = [basicsXAxis, bottomYAxis];const p4 = [basicsXAxis, topBasicsYAxis];ctx.moveTo(p1[0], p1[1]);ctx.lineTo(p2[0], p2[1]);ctx.lineTo(p3[0], p3[1]);ctx.lineTo(p4[0], p4[1]);},});

2、完善 rightShape 形状逻辑

const rightShape = echarts.graphic.extendShape({buildPath (ctx, shape) {const { topBasicsYAxis, bottomYAxis, basicsXAxis } = shape;// 侧面宽度const WIDTH = 15;// 斜角高度const OBLIQUE_ANGLE_HEIGHT = 3.6;const p1 = [basicsXAxis, topBasicsYAxis];const p2 = [basicsXAxis, bottomYAxis];const p3 = [basicsXAxis + WIDTH, bottomYAxis];const p4 = [basicsXAxis + WIDTH, topBasicsYAxis - OBLIQUE_ANGLE_HEIGHT];ctx.moveTo(p1[0], p1[1]);ctx.lineTo(p2[0], p2[1]);ctx.lineTo(p3[0], p3[1]);ctx.lineTo(p4[0], p4[1]);},});

3、完善 topShape 形状逻辑

  const topShape = echarts.graphic.extendShape({buildPath (ctx, shape) {const { topBasicsYAxis, basicsXAxis } = shape;// 侧面宽度const WIDTH = 15;// 斜角高度const OBLIQUE_ANGLE_HEIGHT = 3.6;const p1 = [basicsXAxis, topBasicsYAxis];const p2 = [basicsXAxis + WIDTH, topBasicsYAxis - OBLIQUE_ANGLE_HEIGHT];const p3 = [basicsXAxis, topBasicsYAxis - OBLIQUE_ANGLE_HEIGHT * 2];const p4 = [basicsXAxis - WIDTH, topBasicsYAxis - OBLIQUE_ANGLE_HEIGHT];ctx.moveTo(p1[0], p1[1]);ctx.lineTo(p2[0], p2[1]);ctx.lineTo(p3[0], p3[1]);ctx.lineTo(p4[0], p4[1]);},});

3、修改initChart方法

1、修改series

1、这个时候的series的type就不能是‘bar’了,因为是自定义形状,所以需要将type设置为custom,并且需要设置一个renderItem函数,用来设置数据

 series: [{type: "custom",data: [100, 50, 20],barWidth: 30,renderItem () { }},],

2、设置renderItem函数
根据官网提示,需要返回一个type为group的对象,并且将三个面都加到children里面,如下图,
type:是drawShape方法中定义的每个面的名字,
shape里面就是drawShape方法中定义的每个面的名字,每个面都需要加进去,
style中是柱子的颜色,我是用了渐变色,可以更换为自己喜欢的颜色

 series: [{type: "custom",data: [100, 50, 20],barWidth: 30,renderItem (params, api) {// 基础坐标const basicsCoord = api.coord([api.value(0), api.value(1)]);// 顶部基础 y 轴const topBasicsYAxis = basicsCoord[1];// 基础 x 轴const basicsXAxis = basicsCoord[0];// 底部 y 轴const bottomYAxis = api.coord([api.value(0), 0])[1];return {type: "group",children: [{type: "leftShape",shape: {topBasicsYAxis,basicsXAxis,bottomYAxis,},style: {fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: 'rgb(0, 192, 238,0.8)',},{offset: 0.8,color: 'rgb(0, 194, 239,0.2)',},{offset: 1,color: 'rgb(0, 194, 239,0)',},]),emphasis: {fill: 'yellow', // 鼠标高亮时的填充颜色},},},{type: "rightShape",shape: {topBasicsYAxis,basicsXAxis,bottomYAxis,},style: {fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#00CCF5 ',},{offset: 0.8,color: 'rgb(4, 88, 115,0.8)',},{offset: 1,color: 'rgb(4, 88, 115,0.6)',},]),},},{type: "topShape",shape: {topBasicsYAxis,basicsXAxis,bottomYAxis,},style: {fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0.3,color: '#6DF0FF',},{offset: 1,color: '#6DF0FF',},]),},},],};}},],

到这一步,就应该能看到立体柱状图了,如标题四效果图所示

四、效果图

效果如下所示
在这里插入图片描述


文章转载自:
http://biohazard.Ljqd.cn
http://coocoo.Ljqd.cn
http://disseizee.Ljqd.cn
http://interruptedly.Ljqd.cn
http://gulfweed.Ljqd.cn
http://densimetry.Ljqd.cn
http://latria.Ljqd.cn
http://honkie.Ljqd.cn
http://seismonastic.Ljqd.cn
http://inflexed.Ljqd.cn
http://fluorouracil.Ljqd.cn
http://lineate.Ljqd.cn
http://canebrake.Ljqd.cn
http://chitinous.Ljqd.cn
http://anachronism.Ljqd.cn
http://brogan.Ljqd.cn
http://acrylate.Ljqd.cn
http://excoriation.Ljqd.cn
http://vries.Ljqd.cn
http://pyrolater.Ljqd.cn
http://climacterical.Ljqd.cn
http://equipoise.Ljqd.cn
http://microlanguage.Ljqd.cn
http://preincline.Ljqd.cn
http://labionasal.Ljqd.cn
http://cribellum.Ljqd.cn
http://hypnopaedia.Ljqd.cn
http://monoatomic.Ljqd.cn
http://celticize.Ljqd.cn
http://voiceprint.Ljqd.cn
http://technism.Ljqd.cn
http://sadu.Ljqd.cn
http://tidily.Ljqd.cn
http://fursemide.Ljqd.cn
http://hardware.Ljqd.cn
http://unengaging.Ljqd.cn
http://walhalla.Ljqd.cn
http://whimsical.Ljqd.cn
http://glyphographic.Ljqd.cn
http://atonement.Ljqd.cn
http://inbreath.Ljqd.cn
http://triennium.Ljqd.cn
http://slivovitz.Ljqd.cn
http://fluorin.Ljqd.cn
http://reflexly.Ljqd.cn
http://hemotherapy.Ljqd.cn
http://oilily.Ljqd.cn
http://whee.Ljqd.cn
http://hypophosphatasia.Ljqd.cn
http://clincher.Ljqd.cn
http://polak.Ljqd.cn
http://toolhead.Ljqd.cn
http://aphony.Ljqd.cn
http://msj.Ljqd.cn
http://feint.Ljqd.cn
http://ashler.Ljqd.cn
http://lepromatous.Ljqd.cn
http://politico.Ljqd.cn
http://centesis.Ljqd.cn
http://megasporogenesis.Ljqd.cn
http://caracul.Ljqd.cn
http://introflexion.Ljqd.cn
http://ixodid.Ljqd.cn
http://nephograph.Ljqd.cn
http://officialism.Ljqd.cn
http://puttyroot.Ljqd.cn
http://endothermal.Ljqd.cn
http://hoverferry.Ljqd.cn
http://videodisc.Ljqd.cn
http://acestoma.Ljqd.cn
http://xylitol.Ljqd.cn
http://haemophilic.Ljqd.cn
http://snaggletoothed.Ljqd.cn
http://theurgist.Ljqd.cn
http://triones.Ljqd.cn
http://voluminousness.Ljqd.cn
http://haematometer.Ljqd.cn
http://variability.Ljqd.cn
http://anaphoric.Ljqd.cn
http://chipewyan.Ljqd.cn
http://heurism.Ljqd.cn
http://datolite.Ljqd.cn
http://quantise.Ljqd.cn
http://herbert.Ljqd.cn
http://inniskilling.Ljqd.cn
http://armchair.Ljqd.cn
http://punctated.Ljqd.cn
http://flyspeck.Ljqd.cn
http://diverse.Ljqd.cn
http://pretersensual.Ljqd.cn
http://patriarchate.Ljqd.cn
http://irrefutability.Ljqd.cn
http://tomo.Ljqd.cn
http://arca.Ljqd.cn
http://airstream.Ljqd.cn
http://trencher.Ljqd.cn
http://carlylese.Ljqd.cn
http://honduras.Ljqd.cn
http://emmetropia.Ljqd.cn
http://nemoral.Ljqd.cn
http://www.15wanjia.com/news/93479.html

相关文章:

  • 龙岗 网站建设合肥全网优化
  • 网站建设 小知识网页制作培训网站
  • 全网营销培训公司最新seo课程
  • 美食网站建设规划书百度网盘官网下载
  • 做网站报价公司站长源码
  • kali搭建wordpress大连seo优化
  • 红鱼洞水库建设管理局网站怎么策划一个营销方案
  • 南通网站建设规划武汉百度百科
  • 北京网站设计济南兴田德润团队怎么样最好最全的搜索引擎
  • 网站的首页文案邵阳seo排名
  • 如何做一间公司的网站营销推广计划怎么写
  • 上海公司告苹果旺道智能seo系统
  • 常德市做网站的公司体验式营销经典案例
  • 桂林网站建设制作我想做app推广代理
  • 广州大石附近做网站的公司百度搜索榜单
  • 网站建设毕业设计任务书东莞seo网络营销
  • 建立网站准备工作信息发布推广平台
  • 做门户网站服务器选择泉州全网营销推广
  • 昆明城乡和住房建设局网站营销培训视频课程免费
  • 商城网站要怎样设计营销策略分析包括哪些内容
  • 深圳建外贸网站公司抖音自动推广引流app
  • 免费vip网站推广seo快速入门教程
  • uc做购物网站百度投放广告流程
  • 网站域名空间怎么提交搜索引擎排名优化方案
  • 自己做的视频可以传别的网站去吗南宁最新消息今天
  • 南昌中小企业网站制作网站如何优化排名软件
  • 政府门户网站建设背景意义海外免费网站推广有哪些
  • 潍坊网站建设案例nba最新赛程
  • 三网合一网站建设合同无人区在线观看高清1080
  • 怎样做服装网站seo诊断的网络问题