Ejemplo n.º 1
0
    def test0(self):
        "Test two strings in drawing."

        path = outputfile("axestest0.ps")
        from reportlab.graphics.charts.axes import XCategoryAxis

        d = XCategoryAxis().demo()
        renderPS.drawToFile(d, path)
Ejemplo n.º 2
0
        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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
 def sample6b():
     "Sample drawing, xcat/yvalue axes, x connected at bottom 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 = 'bottom'
     xAxis.categoryNames = ['Beer', 'Wine', 'Meat', 'Cannelloni']
     xAxis.labels.boxAnchor = 'n'
     drawing.add(xAxis)
     drawing.add(yAxis)
     return drawing
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
        def sample0c():
            "Sample drawing with one xcat axis and two buckets."

            class DDFStyle(ParagraphStyle):
                def __init__(self, **kwds):
                    if 'fillColor' in kwds:
                        kwds['textColor'] = kwds.pop('fillColor')
                    kwds.update({
                        k: v
                        for k, v in (
                            ('name', 'DDFStyle'),
                            ('alignment', 0),
                            ('hyphenationLang', None),
                            ('hyphenationMinWordLength', 4),
                            ('uriWasteReduce', 0.3),
                            ('embeddedHyphenation', 2),
                            ('textColor', colors.blue),
                            ('backColor', colors.yellow),
                        ) if k not in kwds
                    })
                    super().__init__(**kwds)

            drawing = Drawing(400, 200)
            data = [(10, 20)]
            xAxis = XCategoryAxis()
            xAxis.labels.ddfKlass = Paragraph
            xAxis.labels.ddfStyle = DDFStyle
            xAxis.labels.maxWidth = 48
            xAxis.labels.fillColor = colors.red
            xAxis.labels.fontName = 'Helvetica'
            xAxis.labels.fontSize = 12
            xAxis.labels.leading = 12
            xAxis.setPosition(75, 75, 100)
            xAxis.configure(data)
            xAxis.categoryNames = [
                'Ying and Mao\xadTse\xadTung are bonkers',
                'Yang is not a comm\xadun\xadist'
            ]
            xAxis.labels.boxAnchor = 'n'
            drawing.add(xAxis)
            return drawing
Ejemplo n.º 7
0
def axes_demo():
    drawing = shapes.Drawing(width=500, height=300)

    data = [(5, 10, 15, 20), (10, 17, 25, 31)]

    x_axis = XCategoryAxis()
    x_axis.setPosition(100, 100, 350)
    x_axis.configure(data, barWidth=None)
    x_axis.categoryNames = ['Python', 'Ruby', 'C++', 'Haskell', 'Java']
    x_axis.labels.boxAnchor = 'n'
    x_axis.labels[0].angle = 45
    x_axis.labels[0].fontName = 'Times-Bold'
    x_axis.labels[1].fontName = 'Courier'
    x_axis.labels[1].fontSize = 16
    drawing.add(x_axis)

    y_axis = YValueAxis()
    y_axis.setPosition(75, 75, 150)
    y_axis.configure(data)
    drawing.add(y_axis)

    renderPDF.drawToFile(drawing, 'axes_demo.pdf')
Ejemplo n.º 8
0
""")

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)