Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

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

I am using Highcharts graph to display a pie chart. I want to change the tooltip to display the actual data field along with the series name in place of the percentage value.

Here is the sample at jsFiddle

If you check the above sample you will find 2 things

  1. Tooltip is : pointFormat: '{series.name}: ({point.percentage}%)

    ' i.e. Browser share: some-percentage-value

I want to show:

Browser share: 40 (data value instead of percentage)

2. Next is the the display text for each section in the pie. One can see n number of decimals making the graph look very ugly.

I want to show numbers only upto 2 decimal points like percentageDecimals: 1 used in tooltip.

I tried few things for 1st like series.data which returns an array of objects. Also series.data[0]. But no success so far

How can I do both these things?

question from:https://stackoverflow.com/questions/12628673/customize-tooltip-and-format-the-number-to-2-decimal-places-of-highcharts

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can change it so it shows the data value instead by modifying your tooltip pointFormat from pointFormat: '{series.name}: <b>{point.percentage}%</b>', to pointFormat: '{series.name}: <b>{point.y}%</b>',

You can round the numbers by using the Highcharts.numberFormat() function like so in your formatter:

formatter: function() {
    return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2) +' %';
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...