之前没有怎么做过小程序,最近公司需要刚上来就做图表,这对于我来说是一个挑战。
在没做之前觉得没什么,但是后来有一个很大的bug。就是在做Tab切换的时候,我发现页面不管是上下还是左右滑动的时候图表会悬浮在上面,不会随着页面进行移动。
结果发现swiperscroll-view标签下面不能用canvas,这才明白。然后就改用了普通的标签。

这里用的show、hidden隐藏显示

结果如下:切换完之后第二页的图表进行了压缩。看了一下尺寸也没有错啊,到现在也没搞明白怎么回事。于是就换了另一种方式wx:if进行显示和隐藏。把wxml里面注释的内容解开就可以了。把另一个用hidden进行切换的进行注释。


JS:
import * as echarts from ‘../../ec-canvas/echarts’;
const app = getApp();
function initChart(canvas,width,height){
const chart = echarts.init(canvas,null,{
width:width,
height:height
});
canvas.setChart(chart);
var option = {
color: [“#37A2DA”, “#67E0E3”, “#9FE6B8”],
legend: {
data: [‘A’, ‘B’, ‘C’],
top: 10,
left: ‘center’,
backgroundColor: ‘red’,
z: 100
},
grid: {
containLabel: true
},
tooltip: {
show: true,
trigger: ‘axis’
},
xAxis: {
type: ‘category’,
boundaryGap: false,
data: [‘周一’, ‘周二’, ‘周三’, ‘周四’, ‘周五’, ‘周六’, ‘周日’],
// show: false
},
yAxis: {
x: ‘center’,
type: ‘value’,
splitLine: {
lineStyle: {
type: ‘dashed’
}
}
// show: false
},
series: [{
name: ‘A’,
type: ‘line’,
smooth: true,
data: [18, 36, 65, 30, 78, 40, 33]
}, {
name: ‘B’,
type: ‘line’,
smooth: true,
data: [12, 50, 51, 35, 70, 30, 20]
}, {
name: ‘C’,
type: ‘line’,
smooth: true,
data: [10, 30, 31, 50, 40, 20, 10]
}]
};

chart.setOption(option);
return chart;
}
function initChart1(canvas, width, height) {
const chart1 = echarts.init(canvas, null, {
width: width,
height: height
});
canvas.setChart(chart1);

var option = {
color: [‘#37a2da’, ‘#32c5e9’, ‘#67e0e3’],
tooltip: {
trigger: ‘axis’,
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: ‘shadow’ // 默认为直线,可选为:’line’ | ‘shadow’
}
},
legend: {
data: [‘热度’, ‘正面’, ‘负面’]
},
grid: {
left: 15,
right: 20,
bottom: 15,
top: 40,
containLabel: true
},
xAxis: [
{
type: ‘value’,
axisLine: {
lineStyle: {
color: ‘#999’
}
},
axisLabel: {
color: ‘#666’
}
}
],
yAxis: [
{
type: ‘category’,
axisTick: { show: false },
data: [‘汽车之家’, ‘今日头条’, ‘百度贴吧’, ‘一点资讯’, ‘微信’, ‘微博’, ‘知乎’],
axisLine: {
lineStyle: {
color: ‘#999’
}
},
axisLabel: {
color: ‘#666’
}
}
],
series: [
{
name: ‘热度’,
type: ‘bar’,
label: {
normal: {
show: true,
position: ‘inside’
}
},
data: [300, 270, 340, 344, 300, 320, 310],
itemStyle: {
// emphasis: {
// color: ‘#37a2da’
// }
}
},
{
name: ‘正面’,
type: ‘bar’,
stack: ‘总量’,
label: {
normal: {
show: true
}
},
data: [120, 102, 141, 174, 190, 250, 220],
itemStyle: {
// emphasis: {
// color: ‘#32c5e9’
// }
}
},
{
name: ‘负面’,
type: ‘bar’,
stack: ‘总量’,
label: {
normal: {
show: true,
position: ‘left’
}
},
data: [-20, -32, -21, -34, -90, -130, -110],
itemStyle: {
// emphasis: {
// color: ‘#67e0e3’
// }
}
}
]
};

chart1.setOption(option);
return chart1;
}

Page({
data:{
ec: {
onInit: initChart
},
ecA: {
onInit: initChart1
},
clickTab:true,
clickTab1:false,
},
clickTab: function(e){
var that = this;
that.setData({
clickTab: true,
clickTab1: false
})
},
clickTab1: function (e) {
console.log(1111111);
var that = this;
that.setData({
clickTab: false,
clickTab1: true
})
}
})

这样的话就可以正常显示了

微信小程序Tab切换下面的图表显示相关推荐

  1. navtab触底 小程序_微信小程序TAB切换效果

    微信小程序tab切换效果 话不多说,先上效果图 主要是让在一个WXML上面显示2个页面,用来分页展示东西. 直接上代码了: 首先是wxml {{item}} A页 B页 然后是wxcss样式代码 .t ...

  2. 微信小程序 tab切换

    设置背景颜色就直接在page里设置    page {background-color: rgb(242, 242, 242);} tab切换: navigator 页面链接 传参的格式为url=&q ...

  3. 微信小程序 tab切换展示不同的内容

    index.wxml <view class='shopDetail-box'><view class="tab-left" ><view class ...

  4. 微信小程序tab切换

    一:获取数据,初始化存储切换下标的变量以及数据 二:点击切换高亮同时设置子数据 1.定义变量 data: {list:[],//总数据tabIndex:0,//tab切换利用的下标childrenLi ...

  5. 微信小程序tab切换(点击标题切换,滑动屏幕切换)

    效果图: WXML文件 <view class="tab"><scroll-view class="nav" scroll-x="t ...

  6. 微信小程序——tab切换内容

    wxml: wxss: js: .wxml代码: <view class="body">   <view class="nav bc_white&quo ...

  7. 解决微信小程序的wx-charts插件tab切换时的显示会出现位置移动问题-tab切换时,图表显示错乱-实现滑动tab

    解决Echarts在微信小程序tab切换时的显示会出现位置移动问题 tab切换时,图表显示错乱 <canvas class="kcanvas" canvas-id=" ...

  8. 微信小程序Tab选项卡切换大集合

    代码地址如下: http://www.demodashi.com/demo/14028.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.c ...

  9. PHP更新小程序,微信小程序Tab页切换更新数据详细介绍

    这篇文章主要介绍了微信小程序 Tab页切换更新数据的相关资料,需要的朋友可以参考下 微信小程序 Tab页切换更新数据 微信小程序还处于内测阶段,最不方便的莫过于官方在不停的更新,前几天写的功能隔个几天 ...

  10. 微信小程序-tab左右滑动切换

    微信小程序-tab左右滑动切换 一.简介 1.核心思想 二.实现 1.wxml实现 2.js实现 3.wxss实现 三.参考和总结 四.优化 0.效果图 1.每个tab长度自适应 2.先前隔tab点击 ...

最新文章

  1. 排查 Node.js 服务内存泄漏,没想到竟是它?
  2. hdu 5155(DP+排列组合)
  3. 一文带你轻松搞懂事务隔离级别(图文详解)
  4. 2017.9.13 序列统计 思考记录
  5. Light OJ 1316 A Wedding Party 最短路+状态压缩DP
  6. Vissim与java(IntelliJ IDEA )联调环境配置
  7. 宋森安——CHARLS中国健康与养老调查数据清洗(一)
  8. 全套AI平面设计软件教程案例素材免费分享
  9. 参数化CFAR的FPGA实现
  10. 拓展练习--find查找、打包压缩、服务器、磁盘挂载
  11. 猎头推荐转行大数据分析师骗局
  12. 分享33个超棒的海洋地貌风光图片
  13. [阿毛]Ubuntu 16安装CH340串口驱动
  14. Vmware安装Ubuntu16.0.4出现Assuming drive cache: write through和1920X1080分辨率调节问题
  15. 滴滴历经7年打磨,终于开源的Kafka云管控平台!Github Star 1.8k+!!
  16. nginx日志格式配置
  17. 数据库—distinct是什么意思?select distinct怎么用?
  18. cadence SPB17.4 - allegro添加过孔
  19. POC和frame_num的概念
  20. 【23考研】计算机择校信息库-浙江高校计算机相关专业22专业目录分类汇总(按专业课分类汇总)

热门文章

  1. 【整数规划算法】分支定界法及其Python代码实现
  2. 全面解析Kmeans聚类算法(Python)
  3. printf()输出格式大全(附 - 示例代码)
  4. 如何更改微信标签名字_微信标签怎么设置?微信怎么批量设置好友标签?
  5. oracle授权怎么收费,Oracle数据库如何授权收费(Database Licensing)
  6. 上海软星解散的前因后果
  7. 经典坦克大战——C++实现(附源码)
  8. After Effects CC 2019 中文版软件下载 /破解教程
  9. 需求分层-KANO模型解读
  10. Java 敏感词过滤工具类及文本