python - Using PyGal, how can I embed a label on the pie chart itself on hover? -


using code below, can generate pie chart. when hover on slice of pie, shows percentage slice occupies.

import pygal results = [     (15232,'value 1'),     (947,'value 2'),     (246,'value 3'),     (117,'value 4'),     (50,'value 5'),     (50,'value 6'),     (50,'value 7'),     (50,'value 8'), ]  pie_chart = pygal.pie() pie_chart.title = 'title!' r in results:     pie_chart.add(r[1], r[0]) pie_chart.value_formatter = lambda x: "%.15f" % x pie_chart.render_to_file('piechart.svg') 

this produces pie chart looks (if hover on "value 2"):

pygal default pie chart

the problem have small slices. it's hard see hovering over. in example above, obvious values 5 through 8, on value 4, it's hard tell 1 being hovered above. there way include label in tool tip well?

the closest i've found value_formater, seems ignored in pie charts (as evidenced example above having 2 decimal places in tooltip, despite pie_chart.value_formatter = lambda x: "%.15f" % x line of code).

the solution utilize label metadata information. requires dictionary, instead of single value, passed second parameter .add() in for loop.

for r in results:     pie_chart.add(r[1], [{'value': r[0], 'label': r[1]}]) 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -