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"

相关推荐
自然 醒9 小时前
uni-app开发微信小程序,如何使用towxml去渲染md格式和html标签格式的内容?
微信小程序·uni-app·html
CHB10 小时前
uni-agent,你的数字员工来了
人工智能·uni-app·vibecoding
h_jQuery10 小时前
uniapp使用canvas实现逐字书写任意文字内容,后合成一张图片提交
前端·javascript·uni-app
困困的果果头10 小时前
【uniapp】解决H5嵌套在web-view中时打包页面与状态栏重叠
前端·uni-app
前端 贾公子10 小时前
Uniapp 使用 UQRCode 创建二维码
uni-app
Rattenking10 小时前
uni-app组件开发----自定义数字键盘组件
前端·javascript·uni-app
笨笨狗吞噬者12 小时前
代理的妙用:uni-app 小程序是怎样用 `Proxy` 和 `wrapper` 抹平平台差异的
前端·微信小程序·uni-app
软希网分享源码2 天前
中英双语言量化交易投资源码/跟单搬砖区块链交易所源码/前端uniapp纯源码+后端
前端·uni-app·区块链·中英双语言量化交易投资源码
小成Coder2 天前
UniApp 如何调用鸿蒙预加载
uni-app·harmonyos·鸿蒙