jqplot:如何显示小数位

8
我正在使用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);
          }
      );

它目前可以正常工作,但是在柱状图标签上去掉了小数位并将值舍入到最近的整数。我该如何停止这种情况并显示正确的两位小数结果?我尝试使用formatString: "\u00A3\%'d%.2f",但似乎是在此之前格式化字符串。

我正在使用jqplot.barRenderer.min.js、jqplot.categoryAxisRenderer.min.js和jqplot.pointLabels.min.js。

1个回答

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

如果您只想保留小数点后一位,可以使用“%#.1f”,如果您想显示百分号,则使用“%#.2f%”。只是以防万一有人不愿意尝试 ;) - R. Mo
我有同样的问题,但这并不能解决我的问题。我的数据有3位小数,但显示为1或2位小数(在不同的图之间变化!)。有什么想法吗? - Roman
@Roman Chris Leonello [开发者] 2011年9月14日 回复:在轴标签中添加小数位数[剪辑]我在第849版中增强了轴,根据刻度间隔自动计算一个好的格式字符串。[/剪辑]https://groups.google.com/forum/#!msg/jqplot-users/lMs1Ni1oOJ0/sLqFTRpdAiYJ也许这可能会影响它。我还没有找到基于该参考的提交... - twobob

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接