Chartjs 工具提示换行符 [英] Chartjs Tooltip Line Breaks

查看:18
本文介绍了Chartjs 工具提示换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 chartjs 工具提示中获得换行符?

Is it possible to get line breaks in chartjs tooltips?

tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>"

我想用新的一行替换:".

I want to replace ": " with a new line.

我试过 &#013;u000D <br/> 无济于事.

I've tried with &#013;, u000D, and <br /> to no avail.

更新:现在我已将接受的答案更改为 chart.js 是第 2 版.

Update: I have changed my accepted answer now that chart.js is on version 2.

推荐答案

如果您使用的是 2.0.0-beta2,您可以使用 tooltip 回调并在此处返回字符串数组.

If you are using 2.0.0-beta2, you can use tooltip callback and return array of strings there.

tooltips: {
    mode: 'single',
    callbacks: {
        afterBody: function(data) {
            var multistringText = ['first string'];
            // do some stuff
            multistringText.push('another string');

            return multistringText;
        }
    }
}

这篇关于Chartjs 工具提示换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆