pygal
pygal copied to clipboard
x_labels line breaks
First I'd like to thank you for creating such a wonderful library/tool! However I was wondering if it's possible to have line breaks in the x_labels
. Currently adding \n
adds an actual line break in the SVG file which isn't rendered. I noticed this issue has been addressed with the tooltips
but doesn't appear to be working for x_labels
.
Thanks
Have you tried to set the css for the element to have white-space: pre-line. E.G.
config = pygal.Config()
# make plot title larger and add linebreaks
config.css.append('''inline:
g.titles text.plot_title {
font-size: 18px !important;
white-space: pre-line;
}''')
chart = pygal.Pie(config,
width=300,
height=300,
)
chart.title = "Created by Users \n(%s)"%tracker
in case somebody else is looking here for a solution. Note you will need to change the css selector to target the element you want to use. See: https://svgwg.org/svg-next/text.html#TextLayoutPre.
I would go so far as to suggest changing the css/graph.css file to add white-space: pre-line to:
{{ id }}.title {
text-anchor: middle;
}
so all titles can be split into multiple lines using an embedded \n. \n is unlikely to be added by accident. I am not sure where the multiple line element will end up aligned to the rest of the chart. It could be centered on the location of the original single line. The top line of the wrapped element could be aligned at the same point as the single line. Could even be bottom aligned....