代码之家  ›  专栏  ›  技术社区  ›  curtybear

Chartjs轴断开线记号标签文本

  •  0
  • curtybear  · 技术社区  · 7 年前

    enter image description here

    我正在尝试允许数据对象的标签在空格上断开。我已经浏览了Chartjs文档上的配置选项 tick configuration 允许换行或添加CSS类的功能,在该类中我可以使用换行字规则处理此问题。

    {
        labels: ["Arts Languages and Communication", "Science, Techology and Health", "Business", "Society and Education"],
        datasets: [{label: "Fall 2014", data: [0,0,0,0]}...]
    }
    

    选项对象:

    {
        scales: {
            xAxes: [{ ticks: { /* no available options from docs */ } }]
        }
    }
    

    单词将在空格处打断:

    Arts Language
    and Communication
    
    1 回复  |  直到 7 年前
        1
  •  4
  •   Kunal Khivensara    7 年前

    如果希望xAxis标签包装文本,则需要以这种格式传递数据 labels: [['LONG', 'LONG', 'LONG', 'LABEL'], "Blue", ['YELLOW', 'LONG'], "Green Green", "Purple", "Orange"]

    因此,在您的情况下-> labels:[['Arts Language', 'and Communication'], 'nextLabel', 'otherLabel']

    http://jsfiddle.net/Lzo5g01n/11/

    推荐文章