【问题标题】:Highcharts creating too many values in float [duplicate]Highcharts在浮点数中创建了太多值[重复]
【发布时间】:2013-03-03 22:11:16
【问题描述】:

以下绘制饼图的函数在绘制图表时生成了太多小数点。我应该修改什么以使其仅保留两位小数?代码如下:

$(function () {
var chart;
$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container2',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Risk Score for countries'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage}%</b>',
            percentageDecimals: 1
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Risk Score',
            data: <?php echo json_encode($names1,JSON_NUMERIC_CHECK); ?>
        }]
    });
});

});

【问题讨论】:

    标签: javascript jquery html highcharts


    【解决方案1】:
    formatter: function() {
        return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2); +' %';
    }
    

    并添加工具提示格式

    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage}%</b>',
        percentageDecimals: 1,
        formatter: function() {
            return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2); +' %';
        }
    },
    

    作为PHP number formats

    DEMO

    【讨论】:

    • 它不起作用。图形本身不会生成。我也尝试使用它而不是 highcharts
    • 你的意思是例如24.329489 =&gt; 24.32?如果是,你有两种方法。首先,您可以在 php 代码中对其进行格式化。其次,根据我的建议修改您的 highcharts 格式化程序。 (用于工具提示和 plotOptions)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多