amcharts4饼状图显示百分比的小数点设置

amcharts4的饼状图,通过数据计算的百分比默认是一位的,可以通过设置改为2位
 series.labels.template.text = "{value.percent.formatNumber('#.00')}%";

完整代码如下:

 // Set theme
    am4core.useTheme(am4themes_animated);

    // Generate random data
    var data = {$data};
    var chart = am4core.create("chartdiv", am4charts.PieChart);
    chart.data = data;

    /* Create series */
    var series = chart.series.push(new am4charts.PieSeries());
    series.dataFields.value = "amount";
    series.dataFields.category = "company";

    /* Disable labels */
    series.labels.template.disabled = false;
    series.ticks.template.disabled = false;
    //设置小数点
    series.labels.template.text = "{value.percent.formatNumber('#.00')}%";

    /* Create legend */
    chart.legend = new am4charts.Legend();

    /* Create a separate container to put legend in */
    var legendContainer = am4core.create("legenddiv", am4core.Container);
    legendContainer.width = am4core.percent(100);
    legendContainer.height = am4core.percent(100);
    chart.legend.parent = legendContainer;

    chart.events.on("datavalidated", resizeLegend);
    chart.events.on("maxsizechanged", resizeLegend);

    chart.legend.events.on("datavalidated", resizeLegend);
    chart.legend.events.on("maxsizechanged", resizeLegend);
    function resizeLegend(ev) {
        document.getElementById("legenddiv").style.height = chart.legend.contentHeight + "px";
    }

    chart.exporting.menu = new am4core.ExportMenu();
    chart.exporting.extraSprites.push({
        "sprite": legendContainer,
        "position": "bottom",
        "marginTop": 20
    });

具体看官方demo
https://www.amcharts.com/docs/v4/tutorials/dealing-with-piechart-labels-that-dont-fit/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值