How to set one to red and second to blue?
import pygal
chart = pygal.Line()
chart.x_labels = range(5)
chart.add('one', [1, None, 3, None, 5])
chart.add('two', range(5))
chart.render_to_png(__file__ + '-linear.png')
You can use Pygal's Custom Styles to define specific colors for the series that you are loading. The only drawback is that the colors are assigned based on series order, so in your case you should set the colors parameter to ('red','blue')
so that they match your serie order.
You can add custom styles as follows.
from pygal.style import Style
yourCustomStyle = Style(
...
colors=['#hex_color1', '#hex_color2', ...],
...
)
yourChart = pygal.Line(style=yourCustomStyle)
yourChart.add('Series1', [value1, value2, value3, ...])
yourChart.add('Series2', [value1, value2, value3, ...])
...
yourChart.render()
You have many styling options to change colors, font-size, font-family, background, transparency etc... Check official documentation here
By the time I'm posting this, there is a mistake in the doc though. They have provided tuple of colors rather that a list, for colors
option in their example. You have to use a list[]
for adding colors in your custom styles.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.