uni-app ucharts自定义换行tooltips

实现效果:

第一步:在uni_modules文件夹下找到config-ucharts.js和u-charts.js文件

第二步:在config-ucharts.js文件中配置换行格式

复制代码
// 换行格式
	"wrapTooltip":function(item, category, index, opts){
		return item.name+':'+item.data
	},

第三步:在u-charts.js文件中找到getToolTipData函数,修改换行文本

复制代码
var wrapTitleText = null;
  var textList = seriesData.map(function(item) {
    let titleText = null;
    if (opts.categories && opts.categories.length>0) {
      titleText = categories[index];
    };
	wrapTitleText = titleText;
    return {
      text: option.formatter ? option.formatter(item, titleText, index, opts) : item.name + ': ' + item.data,
      color: item.color,
      legendShape: opts.extra.tooltip.legendShape == 'auto'? item.legendShape : opts.extra.tooltip.legendShape
    };
  });
  textList.unshift({text:wrapTitleText,color:null})
  var offset = {
    x: Math.round(points.x),
    y: Math.round(points.y)
  };
  // console.log("文本"+JSON.stringify(textList))
  return {
    textList: textList,
    offset: offset
  };

第五步:在图表页面引入提示框格式,tooltipFormat="wrapTooltip"

相关推荐
只会安静敲代码的 小周1 小时前
uniapp上传图片时(可选微信头像、相册、拍照)
前端·微信·uni-app
只会安静敲代码的 小周3 小时前
Uniapp微信小程序:轻松获取用户头像和昵称
微信小程序·小程序·uni-app
确实菜,真的爱3 小时前
uniapp自定义底部导航栏,解决下拉时候顶部空白的问题
uni-app
七七小报3 小时前
uniapp-商城-26-顶部模块折叠
uni-app
初遇你时动了情19 小时前
vue3 uniapp vite 配置之定义指令
javascript·vue.js·uni-app
Monly211 天前
Uniapp:列表选择提示框
开发语言·javascript·uni-app
萌萌哒草头将军1 天前
🚀惊了,这个国产软件居然这么牛,比 uniapp 还全能❤️
微信小程序·uni-app·小程序·云开发
大叔_爱编程1 天前
wx219基于ssm+vue+uniapp的教师管理系统小程序
vue.js·小程序·uni-app·毕业设计·ssm·源码·课程设计
不老刘1 天前
uniapp实现图文聊天功能
uni-app
qq_424409191 天前
uniapp的h5,打开的时候,标题会一闪而过应用名称,再显示当前页面的标题
微信小程序·uni-app·html5