答案 0 :(得分:0)
您可以修改labelText
属性以自定义标签。默认情况下,它设置为"[[title]]: [[percents]]%"
,因此将其更改为"[[percents]]%"
即可获得所需内容。
var chart = AmCharts.makeChart("chartdiv", {
// ...
"labelText": "[[percents]]%",
// ...
});
演示如下:
var chart = AmCharts.makeChart( "chartdiv", {
"type": "pie",
"theme": "light",
"labelText": "[[percents]]%",
"dataProvider": [ {
"country": "Lithuania",
"litres": 501.9
}, {
"country": "Czech Republic",
"litres": 301.9
}, {
"country": "Ireland",
"litres": 201.1
}, {
"country": "Germany",
"litres": 165.8
}, {
"country": "Australia",
"litres": 139.9
}, {
"country": "Austria",
"litres": 128.3
}, {
"country": "UK",
"litres": 99
}, {
"country": "Belgium",
"litres": 60
}, {
"country": "The Netherlands",
"litres": 50
} ],
"valueField": "litres",
"titleField": "country",
"balloon":{
"fixedPosition":true
},
"export": {
"enabled": true
}
} );
<script type="text/javascript" src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/pie.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv" style="width: 100%; height: 400px;"></div>
答案 1 :(得分:0)
我知道我来晚了,但是我已经搜寻了好几天,所以我花了足够的时间来找到答案。我的回答只是为了帮助搜索此内容的人找到答案。 我通过覆盖tooltipItem的回调为
解决了此问题options: {
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var label = data.labels[tooltipItem.index];
return `${data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]}`;
}
}
}
}
如果您有多个数据集,并且也想拥有标签,这就是我的工作
callbacks: {
label: function(tooltipItem, data) {
console.log(tooltipItem, data);
var datasetLabel = '';
var label = data.datasets[tooltipItem.datasetIndex].label;
return `${label} : ${data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]}`;
}
}
您可以相应地对其进行修改。 您可以https://jsfiddle.net/18jmzcx2/