本文整理汇总了Python中reportlab.graphics.charts.axes.XCategoryAxis类的典型用法代码示例。如果您正苦于以下问题:Python XCategoryAxis类的具体用法?Python XCategoryAxis怎么用?Python XCategoryAxis使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XCategoryAxis类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
LineChart.__init__(self)
# Allow for a bounding rectangle.
self.strokeColor = None
self.fillColor = None
# Named so we have less recoding for the horizontal one :-)
self.categoryAxis = XCategoryAxis()
self.valueAxis = YValueAxis()
# This defines two series of 3 points. Just an example.
self.data = [(100,110,120,130),
(70, 80, 80, 90)]
self.categoryNames = ('North','South','East','West')
self.lines = TypedPropertyCollection(LineChartProperties)
self.lines.strokeWidth = 1
self.lines[0].strokeColor = colors.red
self.lines[1].strokeColor = colors.green
self.lines[2].strokeColor = colors.blue
# control spacing. if useAbsolute = 1 then
# the next parameters are in points; otherwise
# they are 'proportions' and are normalized to
# fit the available space.
self.useAbsolute = 0 #- not done yet
self.groupSpacing = 1 #5
self.lineLabels = TypedPropertyCollection(Label)
self.lineLabelFormat = None
self.lineLabelArray = None
# This says whether the origin is above or below
# the data point. +10 means put the origin ten points
# above the data point if value > 0, or ten
# points below if data value < 0. This is different
# to label dx/dy which are not dependent on the
# sign of the data.
self.lineLabelNudge = 10
# If you have multiple series, by default they butt
# together.
# New line chart attributes.
self.joinedLines = 1 # Connect items with straight lines.
self.inFill = 0
self.reversePlotOrder = 0
示例2: sample6d
def sample6d():
"Sample drawing, xcat/yvalue axes, x connected at value 20 of y."
drawing = Drawing(400, 200)
data = [(10, 20, 30, 42)]
yAxis = YValueAxis()
yAxis.setPosition(50, 50, 125)
yAxis.configure(data)
xAxis = XCategoryAxis()
xAxis._length = 300
xAxis.configure(data)
xAxis.joinAxis = yAxis
xAxis.joinAxisMode = 'value'
xAxis.joinAxisPos = 20
xAxis.categoryNames = ['Beer', 'Wine', 'Meat', 'Cannelloni']
xAxis.labels.boxAnchor = 'n'
drawing.add(xAxis)
drawing.add(yAxis)
return drawing
示例3: sample0b
def sample0b():
"Sample drawing with one xcat axis and one bucket only."
drawing = Drawing(400, 200)
data = [(10,)]
xAxis = XCategoryAxis()
xAxis.setPosition(75, 75, 300)
xAxis.configure(data)
xAxis.categoryNames = ['Ying']
xAxis.labels.boxAnchor = 'n'
drawing.add(xAxis)
return drawing
示例4: sample1
def sample1():
"Sample drawing containing two unconnected axes."
from reportlab.graphics.shapes import _baseGFontNameB
drawing = Drawing(400, 200)
data = [(10, 20, 30, 42)]
xAxis = XCategoryAxis()
xAxis.setPosition(75, 75, 300)
xAxis.configure(data)
xAxis.categoryNames = ['Beer','Wine','Meat','Cannelloni']
xAxis.labels.boxAnchor = 'n'
xAxis.labels[3].dy = -15
xAxis.labels[3].angle = 30
xAxis.labels[3].fontName = _baseGFontNameB
yAxis = YValueAxis()
yAxis.setPosition(50, 50, 125)
yAxis.configure(data)
drawing.add(xAxis)
drawing.add(yAxis)
return drawing
示例5: disc
""")
disc("""
This drawing shows two axes, one of each kind, which have been created
directly without reference to any chart:
""")
from reportlab.graphics import shapes
from reportlab.graphics.charts.axes import XCategoryAxis,YValueAxis
drawing = Drawing(400, 200)
data = [(10, 20, 30, 40), (15, 22, 37, 42)]
xAxis = XCategoryAxis()
xAxis.setPosition(75, 75, 300)
xAxis.configure(data)
xAxis.categoryNames = ['Beer', 'Wine', 'Meat', 'Cannelloni']
xAxis.labels.boxAnchor = 'n'
xAxis.labels[3].dy = -15
xAxis.labels[3].angle = 30
xAxis.labels[3].fontName = 'Times-Bold'
yAxis = YValueAxis()
yAxis.setPosition(50, 50, 125)
yAxis.configure(data)
drawing.add(xAxis)
drawing.add(yAxis)
示例6: generateGraphs
def generateGraphs(self, x, y):
(x1, y1, Width, Height) = self._getGraphRegion(x, y)
#Draw Axes
yVAxis = YValueAxis()
#If we got numeric X vals, we use a ValueAxis, otherwise CategoryAxis.
if len(self.x_vals) > 0:
if isinstance(self.x_vals[0], str):
xVAxis = XCategoryAxis()
else:
xVAxis = XValueAxis()
else:
return -1
(y_min, y_max, y_step) = self.getValueAxisScale(yVAxis, [self.y_vals])
if y_min == -1 and y_min == -1 and y_step == -1:
return -1
(self.valueMin, self.valueMax, self.valueStep) = (y_min, y_max, y_step)
(SizeXaxis, SizeYaxis) = self.getSizes()
#lot of ugliness in here to get the split chart working :|
if self.betweenSplitsF == True:
if self.numSplits == 0:
self.tmpYVal = SizeYaxis
else:
SizeYaxis = self.tmpYVal
if self.numSplits > 0:
xVAxis.visibleLabels = False
xVAxis.visibleTicks = False
X_start_pos = x1 - x + SizeYaxis
X_width = Width - SizeYaxis - 10
if self.betweenSplitsF == True:
if self.numSplits > 0:
Y_start_pos = y1 - y + SizeXaxis + (self.numSplits *
self.height) - (self.numSplits * 15)
else:
Y_start_pos = y1 - y + SizeXaxis + (self.numSplits *
self.height)
Y_height = Height - SizeXaxis + 40
else:
Y_start_pos = y1 - y + SizeXaxis + (self.numSplits *
self.height)
Y_height = Height - SizeXaxis
xVAxis.setPosition(X_start_pos, Y_start_pos, X_width)
if isinstance(xVAxis, XValueAxis):
dataList = []
dataTuple = reduce(lambda a,b: a + (b,), self.x_vals, ())
dataList.append(dataTuple)
xVAxis.configure(dataList)
xVAxis.labelTextFormat = '%0.' + '%d' % self.xAxisDigits + 'f'
else:
dataList = []
zerodata = [0 for val in self.x_vals]
dataTuple = reduce(lambda a,b: a + (b,), zerodata, ())
dataList.append(dataTuple)
xVAxis.configure(dataList)
xVAxis.categoryNames = self.x_vals
#Ugly hack for setting the labels.dy. Empirical: If there are more than 5
#chars, dy = -35 fits fine (assuming the angle would be > 75,when we have
#so long val)
maxLen = 0
for val in self.x_vals:
valLen = len(val)
if valLen > maxLen:
maxLen = valLen
if maxLen > 5:
xVAxis.labels.dy = -35
xVAxis.labels.fontName = 'Helvetica'
xVAxis.labels.fontSize = 7
xVAxis.labels.angle = self.xValsDisplayAngle
drawLegendF = False
if len(self.legendList) > 0:
drawLegendF = True
drawLabelF = False
lblCounts = len(self.x_vals) * len(self.y_vals)
if lblCounts <= 30 and self.displayDataLbls == True:
drawLabelF = True
if len(self.x_vals) == 1:
drawLabelF = True
#hack to increase chart height to include legend and labels
total_height = 0
legendHeight = 0
if drawLegendF == True:
#Kludge: We enchroach the space needed for legends by bringing down the
#y value by 28 (in drawOn()), we use that space here
legendHeight = Y_height + 28
graph_height = Y_height
yVAxis.setPosition(X_start_pos, Y_start_pos, Y_height)
yVAxis.valueMin = y_min
yVAxis.valueMax = y_max
yVAxis.valueStep = y_step
yVAxis.labels.fontName = 'Helvetica'
yVAxis.labels.fontSize = 7
yVAxis.labelTextFormat = '%0.' + '%d' % self.yAxisDigits + 'f'
yVAxis.configure(self.y_vals)
#will later sync the yVAxis as the ValueAxis of the graph
self.drawing.add(xVAxis)
if self.numSplits == 0:
#.........这里部分代码省略.........
示例7: HorizontalLineChart
class HorizontalLineChart(LineChart):
"""Line chart with multiple lines.
A line chart is assumed to have one category and one value axis.
Despite its generic name this particular line chart class has
a vertical value axis and a horizontal category one. It may
evolve into individual horizontal and vertical variants (like
with the existing bar charts).
Available attributes are:
x: x-position of lower-left chart origin
y: y-position of lower-left chart origin
width: chart width
height: chart height
useAbsolute: disables auto-scaling of chart elements (?)
lineLabelNudge: distance of data labels to data points
lineLabels: labels associated with data values
lineLabelFormat: format string or callback function
groupSpacing: space between categories
joinedLines: enables drawing of lines
strokeColor: color of chart lines (?)
fillColor: color for chart background (?)
lines: style list, used cyclically for data series
valueAxis: value axis object
categoryAxis: category axis object
categoryNames: category names
data: chart data, a list of data series of equal length
"""
_attrMap = AttrMap(BASE=LineChart,
useAbsolute = AttrMapValue(isNumber, desc='Flag to use absolute spacing values.',advancedUsage=1),
lineLabelNudge = AttrMapValue(isNumber, desc='Distance between a data point and its label.',advancedUsage=1),
lineLabels = AttrMapValue(None, desc='Handle to the list of data point labels.'),
lineLabelFormat = AttrMapValue(None, desc='Formatting string or function used for data point labels.'),
lineLabelArray = AttrMapValue(None, desc='explicit array of line label values, must match size of data if present.'),
groupSpacing = AttrMapValue(isNumber, desc='? - Likely to disappear.'),
joinedLines = AttrMapValue(isNumber, desc='Display data points joined with lines if true.'),
lines = AttrMapValue(None, desc='Handle of the lines.'),
valueAxis = AttrMapValue(None, desc='Handle of the value axis.'),
categoryAxis = AttrMapValue(None, desc='Handle of the category axis.'),
categoryNames = AttrMapValue(isListOfStringsOrNone, desc='List of category names.'),
data = AttrMapValue(None, desc='Data to be plotted, list of (lists of) numbers.'),
inFill = AttrMapValue(isBoolean, desc='Whether infilling should be done.',advancedUsage=1),
reversePlotOrder = AttrMapValue(isBoolean, desc='If true reverse plot order.',advancedUsage=1),
annotations = AttrMapValue(None, desc='list of callables, will be called with self, xscale, yscale.',advancedUsage=1),
)
def __init__(self):
LineChart.__init__(self)
# Allow for a bounding rectangle.
self.strokeColor = None
self.fillColor = None
# Named so we have less recoding for the horizontal one :-)
self.categoryAxis = XCategoryAxis()
self.valueAxis = YValueAxis()
# This defines two series of 3 points. Just an example.
self.data = [(100,110,120,130),
(70, 80, 80, 90)]
self.categoryNames = ('North','South','East','West')
self.lines = TypedPropertyCollection(LineChartProperties)
self.lines.strokeWidth = 1
self.lines[0].strokeColor = colors.red
self.lines[1].strokeColor = colors.green
self.lines[2].strokeColor = colors.blue
# control spacing. if useAbsolute = 1 then
# the next parameters are in points; otherwise
# they are 'proportions' and are normalized to
# fit the available space.
self.useAbsolute = 0 #- not done yet
self.groupSpacing = 1 #5
self.lineLabels = TypedPropertyCollection(Label)
self.lineLabelFormat = None
self.lineLabelArray = None
# This says whether the origin is above or below
# the data point. +10 means put the origin ten points
# above the data point if value > 0, or ten
# points below if data value < 0. This is different
# to label dx/dy which are not dependent on the
# sign of the data.
self.lineLabelNudge = 10
# If you have multiple series, by default they butt
# together.
# New line chart attributes.
self.joinedLines = 1 # Connect items with straight lines.
self.inFill = 0
self.reversePlotOrder = 0
#.........这里部分代码省略.........
示例8: disc
disc(
"""
This drawing shows two axes, one of each kind, which have been created
directly without reference to any chart:
"""
)
from reportlab.graphics import shapes
from reportlab.graphics.charts.axes import XCategoryAxis, YValueAxis
drawing = Drawing(400, 200)
data = [(10, 20, 30, 40), (15, 22, 37, 42)]
xAxis = XCategoryAxis()
xAxis.setPosition(75, 75, 300)
xAxis.configure(data)
xAxis.categoryNames = ["Beer", "Wine", "Meat", "Cannelloni"]
xAxis.labels.boxAnchor = "n"
xAxis.labels[3].dy = -15
xAxis.labels[3].angle = 30
xAxis.labels[3].fontName = "Times-Bold"
yAxis = YValueAxis()
yAxis.setPosition(50, 50, 125)
yAxis.configure(data)
drawing.add(xAxis)
drawing.add(yAxis)
示例9: generatePdfReport
def generatePdfReport(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
# Create the PDF object, using the response object as its "file."
p = canvas.Canvas(response)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
Title="Test Report"
PAGE_HEIGHT=defaultPageSize[1]
PAGE_WIDTH=defaultPageSize[0]
p.drawCentredString(PAGE_WIDTH/2.0, PAGE_HEIGHT-108, Title)
p.drawString(100,900,"Test Configuration")
configuration=request.session["test_configuration"]
data=[['Operation','On/Off','Percentage','Keys','Size']]
if 'readState' in configuration:
readData=[['Read',configuration['readState'],configuration['readPercentage'],configuration['readKeys'],configuration['readSize']]]
else:
readData=[['Read','0','0','0','0']]
data=data+readData
if 'writeState' in configuration:
writeData=[['Write',configuration['writeState'],configuration['writePercentage'],configuration['writeKeys'],configuration['writeSize']]]
else:
writeData=[['Write','0','0','0','0']]
data=data+writeData
if 'updateState' in configuration:
updateData=[['Update',configuration['updateState'],configuration['updatePercentage'],configuration['updateKeys'],configuration['updateSize']]]
else:
updateData=[['Update','0','0','0','0']]
data=data+updateData
table = Table(data, colWidths=100, rowHeights=20)
table.hAlign="CENTER"
table.setStyle(TableStyle())
table.wrapOn(p, 300, 800)
table.drawOn(p,80,550)
p.drawString(80,700,"Test Configuration")
p.drawString(80,500,"Test Time : ")
p.drawString(200,500,str(t1.getTime()) + " miliseconds " )
p.drawString(80,400,"Test Chart")
p.saveState()
drawing = Drawing(10, 10)
data = [(10, 20, 30, 40), (15, 22, 37, 42)]
xAxis = XCategoryAxis()
xAxis.setPosition(75, 75, 300)
xAxis.configure(data)
xAxis.categoryNames = ['Beer', 'Wine', 'Meat', 'Cannelloni']
xAxis.labels.boxAnchor = 'n'
xAxis.labels[3].dy = -15
xAxis.labels[3].angle = 30
xAxis.labels[3].fontName = 'Times-Bold'
yAxis = YValueAxis()
yAxis.setPosition(50, 50, 125)
yAxis.configure(data)
drawing.add(xAxis)
drawing.add(yAxis)
# Close the PDF object cleanly, and we're done.
p.showPage()
p.save()
return response