2013-01-09 12 views
8

sto usando jqplot per mostrare un grafico a barre con:jqplot: Mostra decimali

$.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); 
      } 
    ); 

Si sta lavorando bene, tuttavia, è Escludendo le cifre decimali sulle etichette a barre e l'arrotondamento dei valori di l'int più vicino Come posso fermarlo e mostrare i risultati con le 2 cifre decimali corrette? Ho provato formatString: "\u00A3\%'d%.2f" ma sembrerebbe essere la formattazione della stringa prima che arrivi qui

Sto usando jqplot.barRenderer.min.js, jqplot.categoryAxisRenderer.min.js, jqplot.pointLabels.min.js

risposta

17

Provare a utilizzare formatString: "%#.2f"

+0

Boom! Grazie! – Fraser

+0

e se vuoi solo un posto dopo il decimale è "% #. 1f" e vuoi che il segno% mostri di andare "% #. 2f%" .. solo in caso qualcuno non volesse sperimentare;) –

+0

Ho lo stesso problema, ma questo non lo risolve per me. I miei dati sono disponibili in 3 posizioni decimali, ma sono visualizzati in 1 o 2 cifre decimali (cambia tra i grafici!). Qualche idea? – Roman