这个折线图:
不同样式虚线做数据线:chart.lines[i].strokeDashArray
虚线截小段做图例的色块:
LineLegend,legend.colorNamePairs = Auto(obj = chart)
y轴将给的数据放大1000倍:chart.yValueAxis.labelTextScale
x轴刻度标签旋转90度:chart.xValueAxis.labels.angle
设定x轴上标签的显示格式:
chart.yValueAxis.labelTextFormat
代码及注释:
# 不同样式的数据折线以及指定坐标轴上标签的数据格式from reportlab.graphics.charts.lineplots import LinePlotfrom reportlab.lib.colors import PCMYKColorfrom reportlab.graphics.charts.legends import LineLegendfrom reportlab.graphics.shapes import Drawing, _DrawingEditorMixin, Linefrom reportlab.lib.validators import Autofrom reportlab.lib.styles import blackfrom reportlab.graphics.charts.axes import XValueAxis, YValueAxis, AdjYValueAxis, NormalDateXValueAxisclass LineChart_DashedLinesNumberFormates(_DrawingEditorMixin,Drawing): def __init__(self,width=558,height=140,*args,**kw): Drawing.__init__(self,width,height,*args,**kw) # 公共变量 fontName = 'Helvetica' # 字体 strokeWidth = 0.5 # 线宽 dashArray = (0.3,1) # 虚线样式 lineCap = 1 # 线头样式:0尖头、1圆头、2方头 overShoot = 7.5 # 超出部分 # 添加折线图表 self._add(self,LinePlot(),name='chart',validate=None,desc=None) # 设置x坐标轴 self.chart.xValueAxis = NormalDateXValueAxis() # x轴是个日期轴 self.chart.xValueAxis.labels.fontName = fontName # 日期轴上标签字体 self.chart.xValueAxis.lab