【问题标题】:jqPlot PieRender number formattingjqPlot PieRender 数字格式
【发布时间】:2019-04-18 21:46:18
【问题描述】:

我正在使用 jqplot.PieRenderer 并且需要我的百分比四舍五入到小数点后 2 位。我已将文本标签格式化为包含 ADA 合规性的百分比,因此用户不仅仅依赖图例中与百分比匹配的颜色。但是,我的条形图正在四舍五入为整数。

目前的代码是:

$(document).ready(function(){
    var data = [ OMMITTED_PII_IN_CODE ];
    var plot1 = jQuery.jqplot ('chart1', [data], 
        { 
            seriesDefaults: {
                // Make this a pie chart.
                renderer: jQuery.jqplot.PieRenderer, 
                rendererOptions: {
                    // Put data labels on the pie slices.
                    // By default, labels show the percentage of the slice.
                    showDataLabels: true
                }
            }, 

            legend: { 
                show:true, 
                location: 's',
                border: '0px',
                fontSize: '12px',
                // Breaks the ledgend into horizontal.
                rendererOptions: {
                    numberRows: '4',
                    numberColumns: '3'
                }
            }
            ,
            series: [{color:"#000000"}],
            seriesColors: ["#d1ded4","#b8c8bb","#7a9f83","#F4D03F","#337ab7","#ccc","#fcf8e3","#f2dede"],
            title: {
                text: 'WVSOM Contributions Breakdown'
            }


        }
    ); // end plot chart
    }); // end document ready

【问题讨论】:

    标签: jqplot


    【解决方案1】:

    您可以使用dataLabelFormatString 指定您希望段中的标签的格式。如果您在rendererOptions 中定义以下内容,它将显示到小数点后两位:

    dataLabelFormatString: '%#.2f%'
    

    %#.2f 告诉它显示到小数点后 2 位,末尾的 % 将在数字后显示一个百分号。

    你会得到这样的结果:

    有关工作示例,请参阅 this Fiddle

    【讨论】:

      猜你喜欢
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 2013-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多