0

所以我使用 jQuery 插件“Highcharts”制作了这个饼图,它返回给我的是输入它的总数的百分比。我还想做的是专门显示传递给插件的数字。这是否可能以及如何通过登录系统阻止我拥有的内容,但此链接指向我正在使用的确切演示:

http://www.highcharts.com/demo/pie-legend

如果您查看源代码,您将看到插件的以下内容:

$(function () {
    var chart;

    $(document).ready(function () {

        // Build the chart
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: 'Browser market shares at a specific website, 2010'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                percentageDecimals: 1
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            },
            series: [{
                type: 'pie',
                name: 'Browser share',
                data: [
                    ['Firefox',   45.0],
                    ['IE',       26.8],
                    {
                        name: 'Chrome',
                        y: 12.8,
                        sliced: true,
                        selected: true
                    },
                    ['Safari',    8.5],
                    ['Opera',     6.2],
                    ['Others',   0.7]
                ]
            }]
        });
    });

});

Under "data" there is the series title and then the value. I specifically want to know what syntax to use to display the numbers like "Firefox"'s 45.0. To display the title you use {series.name} so I am guessing its something like {series.number} but there isn't anywhere in the documentation that specifies this so I am not sure if its even possible. Any help would be appreciated!

4

2 回答 2

0

I actually found the answer but not through Highcharts documentation, if you're wondering in the formatter you can reference the value you pass to the plugin with this:

this.point.y

Overall my code now looks something like this:

       plotOptions: {
            pie: {
                 allowPointSelect: true,
                 cursor: 'pointer',
                 dataLabels: {
                      enabled: true,
                      color: '#000000',
                      connectorColor: '#000000',
                      formatter: function() {
                           return '<b>'+ this.point.name +'</b>: $'+ this.point.y +' '         + Math.round(this.percentage*10)/10 +' %';
                      }
                 }
            }
       },

Customize tooltip and format the number to 2 decimal places of highcharts

于 2013-01-23T19:39:47.990 回答
0

There are two different ways to meet your needs. By using

  1. pointFormat
  2. Formatting your Tool tip.

Using pointFormat

Add the following snippet

 tooltip: {
            pointFormat: '{series.name}: <b>{point.y}</b>'                 
          }

Find the demo here.

Using Formatter

The code

tooltip: {
            formatter: function () {
                return '<b>' + this.point.name + '</b>: ' + this.point.y
            }
        }

Find the demo here.

In your code,

tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage}%</b>',
            percentageDecimals: 1
        },

replace,

 pointFormat: '{series.name}: <b>{point.percentage}%</b>'

with

 pointFormat: '{series.name}: <b>{point.y}</b>',
于 2013-01-25T07:29:00.940 回答