jqplot:显示小数位数

时间:2013-01-09 11:52:40

标签: jquery jqplot

我正在使用jqplot显示条形图:

$.jqplot.config.enablePlugins = true;
      var s1 = [8916.55, 1860.45, 60.33];
      var ticks = ['Total Cost', 'Total Chargeable', 'Total Invoiced'];

      plot1 = $.jqplot('chart_div', [s1], {
          // Only animate if we're not using excanvas (not in IE 7 or IE 8)..
          seriesColors: ["#009DDE", "lightgreen", "green"],
          animate: !$.jqplot.use_excanvas,
          seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            pointLabels: { show: true },
            rendererOptions:{ 
              varyBarColor : true,
              animation: {
                speed: 1000
              }
            }
          },
          axes: {
              xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
              },
              yaxis: {
                tickOptions:{
                  formatString: "\u00A3\%'d"
                }
              }
          },
          highlighter: { 
            show: false 
          },

      });

      $('#chart1').bind('jqplotDataClick', 
          function (ev, seriesIndex, pointIndex, data) {
              $('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
          }
      );

它工作正常,但它会剥离条形标签上的小数位并将值四舍五入到最近的int。如何停止此操作并将结果显示到正确的2位小数?我试过formatString: "\u00A3\%'d%.2f",但它似乎是在字符串到达​​之前格式化

我正在使用 jqplot.barRenderer.min.js, jqplot.categoryAxisRenderer.min.js, jqplot.pointLabels.min.js

1 个答案:

答案 0 :(得分:18)

尝试使用formatString: "%#.2f"