How to show values ​​in areas of jqplot chart instead of percentage

I have javascript code like:

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]); 

Now, using dataLabels: 'value', I can show the values, but the value 51 is shown instead of 50.667. The value is rounded. But I need to show the exact meaning. Like this?

My second question: when I have a mouse pointer on any area of ​​the chart, I want to show something. This will be done using jqplotDataMouseOver. But how to use it? Thanks in advance .Plz immediately responds as urgent.

+7
source share
1 answer

Your first question can be resolved using the dataLabelFormatString property:

 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' will display 4 decimal places.

Your second question is more complicated. Obviously, the events on the histograms are not completely smoothed out using jqplot. But the last sentence in this link works for me:

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

Here's jsfiddle , don't forget to cache JS files since jqplot does not allow hotlinking.

+10
source

All Articles