ucharts提示窗tooltips默认显示格式,显示横轴数据+类别+纵轴数据,如下图所示
现在我们希望横轴类别显示为在第一行显示为标题:
修改ucharts中的config-ucharts.js和u-charts.js
config-ucharts.js中自定义format配置
"myTooltip":function(item, category){
return item.name+" : "+item.data.toFixed(2)
}
在u-charts.js中textList最前头插入一个数据
记得在使用的时候为标签添加相应属性
var myTitleText = null;
var textList = seriesData.map(function(item) {
let titleText = null;
if (opts.categories && opts.categories.length>0) {
titleText = categories[index];
};
myTitleText = 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:myTitleText,color:null});
参考:ucharts tooltip弹窗自定义换行:https://www.bbsmax.com/A/WpdKNAEr5V/