2012-04-03 131 views
7

我的JavaScript代码的区域值:如何显示在jqplot图表,而不是百分比

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

现在通过使用dataLabels:“值”我能显示值,但显示值51而不是50.667。价值圆了。但我需要显示确切的价值。如何?

我的第二个问题是,当我在图表的任何区域上有鼠标指针时,我想显示一些东西。这就是使用jqplotDataMouseOver完成的,但是如何使用它? 在此先感谢。Plz紧急响应。

+0

请给我一些想法。 – ryan 2012-04-04 14:07:01

回答

10

你的第一个问题可以用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'将显示小数点后4位。

你的第二个问题比较困难。 Apparently events on bar charts与jqplot不太相似。但是,在该链接的最后建议,为我的作品:

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

这里有一个jsfiddle,记得缓存JS文件,因为jqplot不允许盗链。