我正在尝试允许数据对象的标签在空格上断开。我已经浏览了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
如果希望xAxis标签包装文本,则需要以这种格式传递数据 labels: [['LONG', 'LONG', 'LONG', 'LABEL'], "Blue", ['YELLOW', 'LONG'], "Green Green", "Purple", "Orange"]
labels: [['LONG', 'LONG', 'LONG', 'LABEL'], "Blue", ['YELLOW', 'LONG'], "Green Green", "Purple", "Orange"]
因此,在您的情况下-> labels:[['Arts Language', 'and Communication'], 'nextLabel', 'otherLabel']
labels:[['Arts Language', 'and Communication'], 'nextLabel', 'otherLabel']
http://jsfiddle.net/Lzo5g01n/11/