ReportLab 图表主题色设置指南
使用 ReportLab 创建图表时,可以通过设置颜色来定义主题色。可以使用 RGB 颜色或 HTML 颜色代码来定义颜色。以下是一个示例:
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
from reportlab.lib import colors
# 定义主题色
theme_color = colors.HexColor('#1f77b4')
# 创建图表
data = [(1, 2, 3, 4), (2, 3, 4, 5), (3, 4, 5, 6)]
drawing = Drawing(400, 200)
chart = VerticalBarChart()
chart.x = 50
chart.y = 50
chart.width = 300
chart.height = 100
chart.data = data
chart.strokeColor = colors.black
chart.fillColor = theme_color
drawing.add(chart)
# 保存图表
drawing.save(formats=['pdf'], outDir='.', fnRoot='chart')
在上面的示例中,我们使用 colors.HexColor() 方法创建一个 RGB 颜色对象,并将其赋值给 theme_color 变量。然后,我们将 fillColor 属性设置为 theme_color,这样图表的颜色就会被设置为主题色。
原文地址: https://www.cveoy.top/t/topic/oN0P 著作权归作者所有。请勿转载和采集!