echarts实现动态渲染多柱图

根据用户选择展示几个柱子

查看数据格式

根据用户查询的条件
在这里插入图片描述
多选系所 展示多个柱子

效果

在这里插入图片描述

处理数据

这里是后端偷懒了 导致前端处理了大量的数据
掉接口获取数据,动态处理数据
在这里插入图片描述
将数据传入这个方法
在这里插入图片描述
这里已经开始组装了,定义一个新的集合用来当做series,看一下series的格式
在这里插入图片描述
是一个数组就代表可以很多根柱子࿰

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
微信小程序中可以使用 echarts-for-weixin 库来实现 echarts 表的渲染。对于折柱混合横向渲染的需求,可以在 echarts 的 option 中设置 xAxis 和 yAxis 的 type 为 'value',同时设置 grid 中的 containLabel 为 true,让表可以占满整个 canvas 区域。 具体的实现步骤如下: 1. 安装 echarts-for-weixin 库 ```bash npm install echarts-for-weixin --save ``` 2. 在页面的 JSON 配置中添加 canvas 组件 ```json { "usingComponents": { "ec-canvas": "echarts-for-weixin/ec-canvas" } } ``` 3. 在页面的 WXML 中添加 canvas 组件 ```html <view class="chart-container"> <ec-canvas id="mychart" canvas-id="mychart-canvas" ec="{{ ec }}" /> </view> ``` 4. 在页面的 JS 中引入 echarts 库和 echarts-for-weixin 库 ```javascript import * as echarts from 'echarts'; import * as echartsForWeixin from 'echarts-for-weixin'; ``` 5. 在页面的 JS 中设置 option,并将其传递给 echarts-for-weixin ```javascript Page({ data: { ec: { onInit: initChart } } }); function initChart(canvas, width, height) { const chart = echartsForWeixin.init(canvas, null, { width, height }); const option = { xAxis: { type: 'value', position: 'top' }, yAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, grid: { containLabel: true }, series: [ { name: 'bar', type: 'bar', stack: '总量', label: { show: true }, data: [320, 302, 301, 334, 390, 330, 320] }, { name: 'line', type: 'line', stack: '总量', label: { show: true, position: 'right' }, data: [220, 182, 191, 234, 290, 330, 310] } ] }; chart.setOption(option); return chart; } ``` 在这个例子中,我们将 xAxis 的 type 设置为 'value',并将 yAxis 的 type 设置为 'category'。同时,我们将 xAxis 的 position 设置为 'top',让它位于表上方。为了让表能够横向渲染,我们将 grid 中的 containLabel 设置为 true,这样就可以让表占满整个 canvas 区域了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小莉爱编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值