使用Chartist.js在条形图中的条形内显示文本 [英] Display text inside bar in bar chart with Chartist.js

查看:272
本文介绍了使用Chartist.js在条形图中的条形内显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图使用Chartist.js图表​​在条形图的实际条形图中显示一些文本.最终结果应如下所示:

So, I'm trying to display some text inside the actual bars of a bar chart using Chartist.js charts. The end result should look something like this:

我需要设置哪个属性才能使文本显示在条形图内?

Which property do I need to set in order to get the text inside the bars?

推荐答案

我会使用 chartist- bar-labels 它应该提供您想要的内容,并可以添加以下代码:

I would use chartist-bar-labels it should provide what you are looking for, with it you can add the following code:

Chartist.plugins.ctBarLabels({
      position: {
        x: function (data) {
          return data.x1 + 50
        }
      },
      labelOffset: {
        y: 7
      },
      labelInterpolationFnc: function (text) { //<--- this adds text to your bards
        return text + '%' 
      }
    })

这篇关于使用Chartist.js在条形图中的条形内显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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