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

问题描述 投票:7回答:1

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

现在通过使用dataLabels:'value'我可以显示值,但是显示的值是51而不是50.667。值是四舍五入的。但是我需要显示确切的值。如何做到这一点?

我的第二个问题是,当我将鼠标指针放在图表的任何区域上时,我想显示一些内容。使用jqplotDataMouseOver可以做到这一点,但是如何使用它呢?

javascript jquery charts onclick jqplot
1个回答
11
投票
您的第一个问题可以使用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' } },

© www.soinside.com 2019 - 2024. All rights reserved.