【问题标题】:How to show the values on the regions of the jqplot chart instead of percentage如何在 jqplot 图表的区域上显示值而不是百分比
【发布时间】:2012-04-03 12:05:48
【问题描述】:

我的 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】:

    您的第一个问题可以通过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不允许盗链。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-16
      • 1970-01-01
      相关资源
      最近更新 更多