2012-04-03 14 views
7

Mam kodu javascript jako:Jak pokazują wartości w regionach wykresie jqplot zamiast procentu

var plot1 = jQuery.jqplot ('chartdiv', [data], 
{ 
    seriesDefaults: { 
     // Make this a pie chart. 
     renderer: jQuery.jqplot.PieRenderer, 
     rendererOptions: { 
      // Put data labels on the pie slices. 
      // By default, labels show the percentage of the slice. 
      showDataLabels: true, 
      dataLabels: 'value' 
     } 
    }, 
    legend: { show:true, location:'e'} 
}); 


var handler = function(ev, gridpos, datapos, neighbor, plot) { 
    if (neighbor) { 
     alert('x:' + neighbor.data[0] + ' y:' + neighbor.data[1]); 
    } 
}; 

$.jqplot.eventListenerHooks.push(['jqplotClick', handler]); 

Teraz za pomocą dataLabels: „wartość” Jestem w stanie pokazać wartości, ale pokazana wartość jest 51 zamiast 50.667. Wartość jest zaokrąglana. Ale muszę pokazać dokładną wartość. Jak to zrobić?

Moje drugie pytanie jest takie, że gdy mam wskaźnik myszy na dowolnym obszarze wykresu, chcę coś pokazać. Jest to zrobione przy użyciu jqplotDataMouseOver. Ale jak z niego korzystać? Dzięki z góry.Plz reagować natychmiast, ponieważ jest to pilne.

+0

Proszę, daj mi jakiś pomysł. – ryan

Odpowiedz

10

Twoje pierwsze pytanie może być rozwiązany za pomocą właściwości dataLabelFormatString:

seriesDefaults: { 
     // Make this a pie chart. 
     renderer: jQuery.jqplot.PieRenderer, 
     rendererOptions: { 
      // Put data labels on the pie slices. 
      // By default, labels show the percentage of the slice. 
      showDataLabels: true, 
      dataLabels: 'value', 
      dataLabelFormatString:'%.4f' 
     } 
    }, 

'%.4f' pokaże 4 miejsc po przecinku.

Twoje drugie pytanie jest trudniejsze. Apparently events on bar charts nie są całkiem wyprasowane za pomocą jqplot. Ale ostatnia propozycja w tym linku działa dla mnie:

$('#chartdiv').bind('jqplotDataMouseOver', function (ev, seriesIndex, pointIndex, data) { alert('series: '+seriesIndex+', point: '+pointIndex+', data: '+data)}); 

Oto jsfiddle, należy pamiętać, aby buforować pliki JS od jqplot nie pozwala hotlinking.