Ejemplo n.º 1
0
    def __init__(self, data=None, legend_data=None):
        Drawing.__init__(self, width=530, height=160)

        self._add(self,
                  MyChartFrame(x=0, y=0, width=530, height=160,
                               title='Volume'),
                  name='frame')

        # chart
        self._add(self, LinePlot(), name='chart')
        self.chart.y = 20
        self.chart.x = 34
        self.chart.width = 423
        self.chart.height = 110

        # line styles
        self.chart.lines.symbol = makeMarker('Circle', size=2)

        colors = map(toColor, get_n_random_colors(len(legend_data)))
        for (i, _) in enumerate(legend_data):
            self.chart.lines[i].strokeColor = colors[i]

        # x axis
        self.chart.xValueAxis = NormalDateXValueAxis()
        self.chart.xValueAxis.xLabelFormat = '{dd} {MMM}'
        self.chart.xValueAxis.loLLen = 8
        self.chart.xValueAxis.hiLLen = 5
        self.chart.xValueAxis.labels.fontName = 'Lato'
        self.chart.xValueAxis.labels.fontSize = 9

        # y axis
        self.chart.yValueAxis = YValueAxis()
        self.chart.yValueAxis.visibleGrid = 1
        self.chart.yValueAxis.visibleAxis = 0
        self.chart.yValueAxis.strokeWidth = 0.25
        self.chart.yValueAxis.labels.rightPadding = 5
        self.chart.yValueAxis.labels.fontName = 'Lato'
        self.chart.yValueAxis.labels.fontSize = 9
        self.chart.yValueAxis.rangeRound = 'both'
        self.chart.yValueAxis.tickLeft = 7.5
        self.chart.yValueAxis.minimumTickSpacing = 0.5
        self.chart.yValueAxis.maximumTicks = 8
        self.chart.yValueAxis.avoidBoundFrac = 0.1

        # legend
        self._add(self, LineLegend(), name='legend')
        self.legend.alignment = 'right'
        self.legend.y = 110
        self.legend.x = 462
        self.legend.dxTextSpace = 5
        self.legend.columnMaximum = 4
        self.legend.fontName = 'Lato'
        self.legend.fontSize = 9

        self.legend.colorNamePairs = zip(colors, legend_data)

        # Data...
        self.chart.data = data
Ejemplo n.º 2
0
 def sample5d():
     "Sample drawing, xvalue/yvalue axes, y connected at left of x."
     drawing = Drawing(400, 200)
     data = [(10, 20, 30, 42)]
     xAxis = XValueAxis()
     xAxis.setPosition(50, 50, 300)
     xAxis.configure(data)
     yAxis = YValueAxis()
     yAxis.setPosition(50, 50, 125)
     yAxis.joinAxis = xAxis
     yAxis.joinAxisMode = 'left'
     yAxis.configure(data)
     drawing.add(xAxis)
     drawing.add(yAxis)
     return drawing
Ejemplo n.º 3
0
 def sample4d():
     "Sample drawing, xvalue/yvalue axes, y connected to top of x."
     drawing = Drawing(400, 200)
     data = [(10, 20, 30, 42)]
     yAxis = YValueAxis()
     yAxis.setPosition(50, 50, 125)
     yAxis.configure(data)
     xAxis = XValueAxis()
     xAxis._length = 300
     xAxis.joinAxis = yAxis
     xAxis.joinAxisMode = 'top'
     xAxis.configure(data)
     drawing.add(xAxis)
     drawing.add(yAxis)
     return drawing
Ejemplo n.º 4
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.º 5
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.º 6
0
 def sample4c1():
     "xvalue/yvalue axes, without drawing axis lines/ticks."
     drawing = Drawing(400, 200)
     data = [(10, 20, 30, 42)]
     yAxis = YValueAxis()
     yAxis.setPosition(50, 50, 125)
     yAxis.configure(data)
     yAxis.visibleAxis = 0
     yAxis.visibleTicks = 0
     xAxis = XValueAxis()
     xAxis._length = 300
     xAxis.joinAxis = yAxis
     xAxis.joinAxisMode = 'bottom'
     xAxis.configure(data)
     xAxis.visibleAxis = 0
     xAxis.visibleTicks = 0
     drawing.add(xAxis)
     drawing.add(yAxis)
     return drawing
Ejemplo n.º 7
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.º 8
0
    def __init__(self, data=None):
        Drawing.__init__(self, width=458, height=130)

        # chart
        self._add(self, LinePlot(), name='chart')
        self.chart.y = 20
        self.chart.x = 60
        self.chart.width = 320
        self.chart.height = 100

        # line styles
        self.chart.lines.symbol = makeMarker('Circle', size=2)

        colors = map(toColor, get_n_random_colors(len(data)))
        for (i, _) in enumerate(data):
            self.chart.lines[i].strokeColor = colors[i]

        # x axis
        self.chart.xValueAxis = NormalDateXValueAxis()
        self.chart.xValueAxis.xLabelFormat = '{dd} {MMM}'
        self.chart.xValueAxis.loLLen = 8
        self.chart.xValueAxis.hiLLen = 5
        self.chart.xValueAxis.labels.fontName = 'Lato'
        self.chart.xValueAxis.labels.fontSize = 9

        # y axis
        self.chart.yValueAxis = YValueAxis()
        self.chart.yValueAxis.visibleGrid = 1
        self.chart.yValueAxis.visibleAxis = 0
        self.chart.yValueAxis.strokeWidth = 0.25
        self.chart.yValueAxis.labels.rightPadding = 5
        self.chart.yValueAxis.labels.fontName = 'Lato'
        self.chart.yValueAxis.labels.fontSize = 9
        self.chart.yValueAxis.rangeRound = 'both'
        self.chart.yValueAxis.tickLeft = 7.5
        self.chart.yValueAxis.minimumTickSpacing = 0.5
        self.chart.yValueAxis.maximumTicks = 8
        self.chart.yValueAxis.avoidBoundFrac = 0.1

        # Data...
        self.chart.data = data
Ejemplo n.º 9
0
    def __init__(self):
        PlotArea.__init__(self)
        self.reversePlotOrder = 0

        self.xValueAxis = XValueAxis()
        self.yValueAxis = YValueAxis()

        # this defines two series of 3 points.  Just an example.
        self.data = [
            ((1,1), (2,2), (2.5,1), (3,3), (4,5)),
            ((1,2), (2,3), (2.5,2), (3,4), (4,6))
            ]

        self.lines = TypedPropertyCollection(LinePlotProperties)
        self.lines.strokeWidth = 1
        self.lines[0].strokeColor = colors.red
        self.lines[1].strokeColor = colors.blue

        self.lineLabels = TypedPropertyCollection(Label)
        self.lineLabelFormat = None
        self.lineLabelArray = None

        # this says whether the origin is inside or outside
        # the bar - +10 means put the origin ten points
        # above the tip of the bar if value > 0, or ten
        # points inside if bar 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.

        #private attributes
        self._inFill = None
        self.annotations = []
        self.behindAxes = 0
        self.gridFirst = 0
Ejemplo n.º 10
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.º 11
0
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)

draw(drawing, 'Two isolated axes')


disc("Here is the code that created them: ")

eg("""
from reportlab.graphics import shapes
from reportlab.graphics.charts.axes import XCategoryAxis,YValueAxis
Ejemplo n.º 12
0
def getPlot():
    drawing = Drawing(400, 200)
    #temps = [((0.5,7), (1.5,1), (2.5,2), (3.5,1), (4.5,3), (5.5,5), (6.5, 10), (7.5,6))]
    temps = [getTemps()]
    bc = LinePlot()
    bc.x = 50
    bc.y = 50
    bc.height = 125
    bc.width = 300
    bc.data = temps
    #labels
    yilabel = Label()
    yilabel.setText("Temperatura (°C)")
    yilabel.angle = 90
    yilabel.setOrigin(20,120)
    xlabel = Label()
    xlabel.setText("Días")
    xlabel.setOrigin(200,20)

    labelT = Label()
    labelT.setText("Temperatura")
    labelT.setOrigin(210,185)

    labelH = Label()
    labelH.setText("Humedad")
    labelH.setOrigin(285,185)


    bc.xValueAxis.valueMin = 0
    bc.xValueAxis.valueMax = 20
    bc.xValueAxis.valueSteps = [x for x in range(1,bc.xValueAxis.valueMax)]
    #bc.xValueAxis.labelTextFormat = '%2.1f'
    bc.yValueAxis.valueMin = 0
    bc.yValueAxis.valueMax = 60
    bc.yValueAxis.valueSteps = [0, 10, 20, 30, 40, 50, 60]
    drawing.add(bc)
    drawing.add(yilabel)
    drawing.add(xlabel)
    drawing.add(Line(170,185,185,185, strokeColor=colors.red))
    drawing.add(Line(250,185,265,185, strokeColor=colors.blue))
    drawing.add(labelT)
    drawing.add(labelH)

    #humedad=[[(0.5, 4), (1.5, 3), (2.5, 4), (3.5, 6), (4.5, 4), (5.5, 2), (6.5, 5), (7.5, 6)]]
    humedad = [getHumedad()]
    lp = LinePlot()
    lp.x = bc.x
    lp.y = bc.y
    lp.height = bc.height
    lp.width = bc.width
    lp.data = humedad

    ydlabel = Label()
    ydlabel.setText("Humedad (%)")
    ydlabel.angle = -90
    ydlabel.setOrigin(lp.x+lp.width+30,lp.y+70)

    lp.joinedLines = 1
    lp.lines[0].symbol = makeMarker('Circle')
    lp.lines[0].strokeColor=colors.blue
    lp.lineLabelFormat = '%2.0f'
    lp.xValueAxis.valueMin = 0
    lp.xValueAxis.valueMax = bc.xValueAxis.valueMax
    lp.yValueAxis.valueMin = 0
    lp.yValueAxis.valueMax = 100
    lp.xValueAxis.visible=False
    lp.yValueAxis.visible=False #Hide 2nd plot its Yaxis
    drawing.add(lp)
    drawing.add(ydlabel)

    y2Axis = YValueAxis()#Replicate 2nd plot Yaxis in the right
    y2Axis.setProperties(lp.yValueAxis.getProperties())
    y2Axis.setPosition(lp.x+lp.width,lp.y,lp.height)
    y2Axis.tickRight=5
    y2Axis.tickLeft=0
    y2Axis.labels.dx = 20
    y2Axis.configure(humedad)
    y2Axis.visible=True
    drawing.add(y2Axis)

    return drawing
Ejemplo n.º 13
0
 def __init__(self):
     LinePlot.__init__(self)
     self.xValueAxis = NormalDateXValueAxis()
     self.yValueAxis = YValueAxis()
     self.data = _monthlyIndexData