问题描述
我正在使用amchart v3,并且正在使用 allLabels 属性显示标题和副标题。但是问题在于,标题没有自动换行,如下图所示
如何将文本“ TOP BUS TYPES:BUS TYPES ”换行到下一行?
下面是我的代码。
const chart = this.AmCharts.makeChart( "mychart",{
"type": "pie","theme": "light","dataProvider": busvalue,"titleField": "title","valueField": "value","labelsEnabled": false,"radius": "40%","innerRadius": "60%","colorField": "color","allLabels": [{
"y": "48%","align": "center","size": 17,"bold": true,"text": 'TOP BUS TYPES: BUS TYPES',"color":'#000000'
},{
"y": "52%","size": 12,"text": ''
"color": '#000000
}],...
});
}
解决方法
在amcharts v3中,没有任何机制可以自动包装免费标签(allLabels
)。您必须根据需要在字符串中插入自己的换行符,例如"text": 'TOP BUS TYPES:\nBUS TYPES'
AmCharts.makeChart("mychart",{
"type": "pie","theme": "light","dataProvider": [{
"title": "1","value": 10
},{
"title": "2",{
"title": "3","value": 10
}],"titleField": "title","valueField": "value","labelsEnabled": false,"radius": "40%","innerRadius": "60%","colorField": "color","allLabels": [{
"y": "48%","align": "center","size": 17,"bold": true,"text": 'TOP BUS TYPES:\nBUS TYPES',"color": '#000000'
},{
"y": "52%","size": 12,"text": '',"color": '#000000'
}]
});
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/pie.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="mychart" style="width: 100%; height: 400px;"></div>