码农的世界python源码大全reportlab教程和源码大全

Python reportlab库之BarChart(含demo

2019-02-19  本文已影响0人  iCloudEnd

条形图

这太常用了,大家直接看代码吧

代码

from reportlab.graphics.shapes import *
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
drawing = Drawing(400, 200)
data = [
 (13, 5, 20, 22, 37, 45, 19, 4),
 (14, 6, 21, 23, 38, 46, 20, 5)
]
bc = VerticalBarChart()
bc.x = 50
bc.y = 50
bc.height = 125
bc.width = 300
bc.data = data
bc.strokeColor = colors.black
bc.valueAxis.valueMin = 0
bc.valueAxis.valueMax = 50
bc.valueAxis.valueStep = 10
bc.categoryAxis.labels.boxAnchor = 'ne'
bc.categoryAxis.labels.dx = 8
bc.categoryAxis.labels.dy = -2
bc.categoryAxis.labels.angle = 30
bc.categoryAxis.categoryNames =['Jan-99','Feb-99','Mar-99','Apr-99','May-99','Jun-99','Jul-99','Aug-99']
drawing.add(bc)
from reportlab.graphics import renderPDF
renderPDF.drawToFile(drawing, 'graphic_barchart.pdf', 'My First Drawing')

效果图


Bar Chart
上一篇下一篇

猜你喜欢

热点阅读