Highcharts single horizontal stacked bar chart wit

2020-04-19 07:17发布

问题:

Is it possible to combine the following?

Fiddle 1 (answered by mäksä) as a main template:

  • Single horizontal stacked bar with bar segments

Combined with the following features of Fiddle 2 (answered by aus_lacy):

Always visible on bar segments:

  • Data names (labels) (i.c. "apples", "pears",...)
  • Percentages (calculated if possible: "50%","50%",...)

Shown on mousehover:

  • Original data numbers (i.c. "15","15",...)
  • Series name/description (i.c. "Browser share")

Almost but not quite:

An example of a horizontal bar chart with "percentages" always shown, and "original data numbers" on mousehover can be found in Fiddle 3 (answered by jlbriggs), but there the "data names" are lacking, and I can't find a way to change the "series name". Further more: this is a horizontal bar chart, but this is not a single stacked one.


Any help would greatly be appreciated, many thanks.

回答1:

Again it's a simple modification of the Highcharts attributes in particular this small snippet:

bar: {
        dataLabels: {
           enabled: true,
           distance : -50,
           formatter: function() {
                 var dlabel = this.series.name + '<br/>';
                 dlabel += Math.round(this.percentage*100)/100 + ' %';
                 return dlabel
           },
           style: {
                 color: 'white',
           },
        },

  },

I think this snippet is what you are after?