2013-01-09 2 views
8
내가 가진 막대 차트를 보여 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

를 사용하고 여기

을 취득하기 전에 문자열을 포맷 할 나타납니다

답변

17

사용해보기 formatString: "%#.2f"

+0

붐! 고맙습니다! – Fraser

+0

그리고 소수점 1 자리를 "% #. 1f"로 표시하고 % 기호를 사용하여 "% #. 2f %"가 표시되도록하려는 경우 누군가가 실험하려고하지 않을 경우에만 입력하십시오.) –

+0

나는 똑같은 문제를 가지고있다. 그러나 이것은 나를 위해 그것을 해결하지 못한다. 내 데이터는 소수 자릿수 3 자리로 표시되지만 소수점 1 자리 또는 2 자리로 표시됩니다 (플롯간에 변경됩니다!). 어떤 아이디어? – Roman