2

How do I add labels on the secondary series of a multiseries pie chart?

Mierzen
  • 566
  • 1
  • 5
  • 25

1 Answers1

1

One way to do it pass in your values as a dictionary.

First import some of the required packages

import pygal
from pygal.style import LightGreenStyle

Initialize the Pygal Pie Object. You can ignore the fancy theme (LightGreenStyle).

pie_chart = pygal.Pie(width=900, height=500, 
                  style=LightGreenStyle, 
                  value_formatter=lambda x: "{}%".format(x))

Here is the part you want.

pie_chart.title = 'Wine Quality Percentage'

pie_chart.add('Good Wines', [{'value': wine_quality_8_percent, 'label': 'Quality Rating - 8'}])

pie_chart.add('Average Wines', [{'value': wine_quality_5_percent, 'label': 'Quality Rating - 5'},
                                {'value': wine_quality_6_percent, 'label': 'Quality Rating - 6'},
                                {'value': wine_quality_7_percent, 'label': 'Quality Rating - 7'}
                               ])

pie_chart.add('Poor Wines', [{'value': wine_quality_3_percent, 'label': 'Quality Rating - 3'},
                            {'value': wine_quality_4_percent, 'label': 'Quality Rating - 4'}])

Notice that values are passed in as a dictionary with 'values' and 'label'. This will get your labels in your multi-series Pie.

enter image description here

this is similar to the labels in regular Pie - Using PyGal, how can I embed a label on the pie chart itself on hover?

mohammed_ayaz
  • 620
  • 11
  • 16