2012-12-26 49 views
3

我正試圖用jqplot生成條形圖。我所有的值都是浮動數字,如下所示:jqplot條形圖將忽略我的浮動數字。如何解決它們?

var s1 = [17.1, 18.2]; 
var s2 = [50.2, 53]; 
var s3 = [93.9, 93]; 
var s4 = [34.1, 34]; 

但它將它們四捨五入爲整數。

這裏是工作示例:http://jsfiddle.net/JkBKs/

我怎樣才能解決這個問題?

+1

y軸: { tickOptions: { formatString的: '%.2f' }} 添加像上面這樣的yaxis格式化固定它。 – ispirto

回答

10

試試這個,它的工作原理

 axes: 
     { 
      xaxis:{ 
       renderer: $.jqplot.CategoryAxisRenderer, 
       ticks: ticks 
      }, 
      yaxis: { 
        labelRenderer: $.jqplot.CanvasAxisLabelRenderer, 
        min: 0 , 
        tickOptions: { 
            formatString: '%.1f' 
           } 

        } 
     }, 
1

請參閱 'formatString的' 內容

seriesDefaults: { 
       renderer:$.jqplot.BarRenderer, 
       // Show point labels to the right ('e'ast) of each bar. 
       // edgeTolerance of -15 allows labels flow outside the grid 
       // up to 15 pixels. If they flow out more than that, they 
       // will be hidden. 
       pointLabels: { show: true, location: 'e', edgeTolerance: -15, formatString: '%.1f' }, 
       // Rotate the bar shadow as if bar is lit from top right. 
       shadowAngle: 135, 
       // Here's where we tell the chart it is oriented horizontally. 
       rendererOptions: { 
        barDirection: 'horizontal' 
       } 
      }, 
      axes: { 
       yaxis: { 
        renderer: $.jqplot.CategoryAxisRenderer 
       } 
      }