score:7

Accepted answer

You can see on the highcharts website the options used to create the pie chart you pasted by clicking on View options.

You'll see, among others, the following code:

plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },

This means you have to enable the dataLabels options and provide a formatter. In the code you provided, you can actually see in the second hc_add_series_labels_values call that the dataLabels enabled options is set to FALSE:

hc_add_series_labels_values(favorite_bars$bar, favorite_bars$percent,
                          colors = substr(terrain.colors(5), 0 , 7), type = "pie",
                          name = "Bar", colorByPoint = TRUE, center = c('35%', '10%'),
                          size = 100, dataLabels = list(enabled = FALSE))

If you change it to TRUE you will see the labels. If you want the numbers to display as well, you have to pass a function to a format element in the list, like so:

hc_add_series_labels_values(favorite_bars$bar, favorite_bars$percent,
                              colors = substr(terrain.colors(5), 0 , 7), type = "pie",
                              name = "Bar", colorByPoint = TRUE, center = c('35%', '10%'),
                              size = 100, dataLabels = list(enabled = TRUE,
                                                            format = '{point.name}: {point.percentage:.1f} %')) 

You'll then have to play with the different options to dataLabels to display them however you want, see the Highcharts API for the Bar chart type for example.


Related Query

More Query from same tag