2015-12-21 138 views
0

我正在使用jqplot来显示图形。jqplot pointLabels如何将数字格式化为2位小数

以下是代码:

tempArr1 = [9189.539999999999, 10170.039999999999, 980.5] 

plot2 = $.jqplot('bar_chart_id1', [tempArr1], { 
          title:{ 
           text: chatTitle2, 
           textColor: '#B66B09' 
          }, 
          seriesDefaults:{ 
           renderer:$.jqplot.BarRenderer, 
           rendererOptions: { 
            // Set the varyBarColor option to true to use different colors for each bar. 
            varyBarColor: true, 
            barPadding: 2, 
            barMargin: 3, 
            barWidth: 30, 
           }, 
           pointLabels: {show: true}, 
          }, 
          axes: { 
           xaxis: { 
            renderer: $.jqplot.CategoryAxisRenderer, 
            ticks: lblArray, 
            label:'Manufacturer', 
           }, 
           yaxis:{ 
            labelRenderer: $.jqplot.CanvasAxisLabelRenderer, 
            min: 0, 
            tickInterval:1000, 
            label:'Amount', 
            tickOptions: {formatString: '$%#.2f'} 
           } 
          }, 
          highlighter: { show: true }, 
         }); 

enter image description here 正如你可以看到点标签中显示许多小数点(9189.539999999999)。 我需要将标签显示为'$ 91890.54'。 我已经尝试了pointLabels中的formatString选项作为'$%#。2',但它不起作用。

任何帮助,非常感谢。 谢谢。

回答

0

回合最多2位小数在JavaScript

Math.round(num * 100)/100 

Source

1
tempArr1 = [9189.539999999999, 10170.039999999999, 980.5]; 
tempArr1 = tempArr1.map(i => { return parseFloat(i.toFixed(2)); }); 
+0

嗨thanx的rply您suggestiond没有工作,但如何我可以在amout之前放置'$'符号。 –

+0

@ShekharKhairnar修改返回'tempArr1 = tempArr1.map(i => {return'$'+ parseFloat(i.toFixed(2));});' – twobob

0
pointLabels: { show: true, location: 'n', lables: tempArr1 , formatString: "$%#.2f" }, 

应满足您的需要

相关问题