如何显示jqplot图表区域的值而不是百分比

rya*_*yan 7 javascript jquery charts onclick jqplot

我有javascript代码:

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]); 
Run Code Online (Sandbox Code Playgroud)

现在通过使用dataLabels:'value'我能够显示值,但显示的值是51而不是50.667.Value是舍入的.但我需要显示确切的值.如何?

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

Mar*_*ark 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'
        }
  }, 
Run Code Online (Sandbox Code Playgroud)

'%.4f'将显示小数点后4位.

你的第二个问题更难. 显然,条形图上的事件并没有完全解决jqplot.但该链接的最后一个建议对我有用:

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

这是一个jsfiddle,记得缓存JS文件,因为jqplot不允许热链接.