示例#1
0
def drawChart(_document, _values, \
      chartWidth,
      chartHeight,
      chartType):
    # Create the subdocument
    chartdoc = OpenDocumentChart()
    mychart = PieChart(chartWidth, chartHeight, chartType)

    # These represent the data. Six rows in three columns
    mychart.values = _values
    mychart.datasourcehaslabels = "both"
    mychart(chartdoc)

    p = P()
    _document.add(p)

    # Create the frame.
    df = draw.Frame(width=chartWidth,
                    height=chartHeight,
                    anchortype="paragraph")
    p.addElement(df)

    # Here we add the subdocument to the main document. We get back a reference
    # to use in the href.
    objectloc = _document.addAsObject(chartdoc)
    do = draw.Object(href=objectloc)

    # Put the object inside the frame
    df.addElement(do)
示例#2
0
        # Title for the Y axis
        yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle)
        plotarea.addElement(yaxis)
        yt = chart.Title()
        yaxis.addElement(yt)
        yt.addElement(text.P(text=self.y_axis))

        # Data area
        datatable = DataTable( self.values )
        datatable.datasourcehaslabels = self.datasourcehaslabels
        mychart.addElement(datatable())

if __name__ == "__main__":
    # Create the document
    doc = OpenDocumentChart()
    mychart = BarChart()
    mychart.title = "SPECTRE"
    mychart.subtitle = "SPecial Executive for Counter-intelligence, Terrorism, Revenge and Extortion"
    mychart.x_axis = u"Divisions"
    mychart.y_axis = u"€ (thousand)"
    # These represent the data. Six rows in three columns
    mychart.values = (
        ('', 'Expense', 'Revenue'),
        ('Counterfeit',  1000, 1500),
        ('Murder',       1100, 1150),
        ('Prostitution', 3200, 2350),
        ('Blackmail',    1100, 1150),
        ('Larceny',      1000, 1750)
    )
    mychart.datasourcehaslabels = "both"
示例#3
0
    def test_chart_style(self):
        """ Test that chart:style-name reference is seen in content.xml """
        doc = OpenDocumentChart()
        chartstyle  = Style(name="chartstyle", family="chart")
        chartstyle.addElement( GraphicProperties(stroke="none", fillcolor="#ffffff"))
        doc.automaticstyles.addElement(chartstyle)

        mychart = chart.Chart( width="576pt", height="504pt", stylename=chartstyle, attributes={'class':'chart:bar'})
        doc.chart.addElement(mychart)

        # Add title
        titlestyle = Style(name="titlestyle", family="chart")
        titlestyle.addElement( GraphicProperties(stroke="none", fill="none"))
        titlestyle.addElement( TextProperties(fontfamily="'Nimbus Sans L'",
                fontfamilygeneric="swiss", fontpitch="variable", fontsize="13pt"))
        doc.automaticstyles.addElement(titlestyle)

        mytitle = chart.Title(x="385pt", y="27pt", stylename=titlestyle)
        mytitle.addElement( text.P(text="Title"))
        mychart.addElement(mytitle)

        # Add subtitle
        subtitlestyle = Style(name="subtitlestyle", family="chart")
        subtitlestyle.addElement( GraphicProperties(stroke="none", fill="none"))
        subtitlestyle.addElement( TextProperties(fontfamily="'Nimbus Sans L'",
                fontfamilygeneric="swiss", fontpitch="variable", fontsize="10pt"))
        doc.automaticstyles.addElement(subtitlestyle)

        subtitle = chart.Subtitle(x="0pt", y="123pt", stylename=subtitlestyle)
        subtitle.addElement( text.P(text="my subtitle"))
        mychart.addElement(subtitle)

        # Legend
        legendstyle = Style(name="legendstyle", family="chart")
        legendstyle.addElement( GraphicProperties(fill="none"))
        legendstyle.addElement( TextProperties(fontfamily="'Nimbus Sans L'",
                fontfamilygeneric="swiss", fontpitch="variable", fontsize="6pt"))
        doc.automaticstyles.addElement(legendstyle)

        mylegend = chart.Legend(legendposition="end", legendalign="center", stylename=legendstyle)
        mychart.addElement(mylegend)

        # Plot area
        plotstyle = Style(name="plotstyle", family="chart")
        plotstyle.addElement( ChartProperties(seriessource="columns",
                percentage="false", stacked="false",
                threedimensional="true"))
        doc.automaticstyles.addElement(plotstyle)

        plotarea = chart.PlotArea(datasourcehaslabels="both", stylename=plotstyle)
        mychart.addElement(plotarea)

        # Style for the X,Y axes
        axisstyle = Style(name="axisstyle", family="chart")
        axisstyle.addElement( ChartProperties(displaylabel="true"))
        doc.automaticstyles.addElement(axisstyle)

        # Title for the X axis
        xaxis = chart.Axis(dimension="x", name="primary-x", stylename=axisstyle)
        plotarea.addElement(xaxis)
        xt = chart.Title()
        xaxis.addElement(xt)
        xt.addElement(text.P(text="x_axis"))

        # Title for the Y axis
        yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle)
        plotarea.addElement(yaxis)
        yt = chart.Title()
        yaxis.addElement(yt)
        yt.addElement(text.P(text="y_axis"))

        result = doc.contentxml()
        self.assertNotEqual(-1, result.find(u'''style:family="chart"'''))
示例#4
0
    def test_chart_style(self):
        """ Test that chart:style-name reference is seen in content.xml """
        doc = OpenDocumentChart()
        chartstyle = Style(name="chartstyle", family="chart")
        chartstyle.addElement(
            GraphicProperties(stroke="none", fillcolor="#ffffff"))
        doc.automaticstyles.addElement(chartstyle)

        mychart = chart.Chart(width="576pt",
                              height="504pt",
                              stylename=chartstyle,
                              attributes={'class': 'chart:bar'})
        doc.chart.addElement(mychart)

        # Add title
        titlestyle = Style(name="titlestyle", family="chart")
        titlestyle.addElement(GraphicProperties(stroke="none", fill="none"))
        titlestyle.addElement(
            TextProperties(fontfamily="'Nimbus Sans L'",
                           fontfamilygeneric="swiss",
                           fontpitch="variable",
                           fontsize="13pt"))
        doc.automaticstyles.addElement(titlestyle)

        mytitle = chart.Title(x="385pt", y="27pt", stylename=titlestyle)
        mytitle.addElement(text.P(text="Title"))
        mychart.addElement(mytitle)

        # Add subtitle
        subtitlestyle = Style(name="subtitlestyle", family="chart")
        subtitlestyle.addElement(GraphicProperties(stroke="none", fill="none"))
        subtitlestyle.addElement(
            TextProperties(fontfamily="'Nimbus Sans L'",
                           fontfamilygeneric="swiss",
                           fontpitch="variable",
                           fontsize="10pt"))
        doc.automaticstyles.addElement(subtitlestyle)

        subtitle = chart.Subtitle(x="0pt", y="123pt", stylename=subtitlestyle)
        subtitle.addElement(text.P(text="my subtitle"))
        mychart.addElement(subtitle)

        # Legend
        legendstyle = Style(name="legendstyle", family="chart")
        legendstyle.addElement(GraphicProperties(fill="none"))
        legendstyle.addElement(
            TextProperties(fontfamily="'Nimbus Sans L'",
                           fontfamilygeneric="swiss",
                           fontpitch="variable",
                           fontsize="6pt"))
        doc.automaticstyles.addElement(legendstyle)

        mylegend = chart.Legend(legendposition="end",
                                legendalign="center",
                                stylename=legendstyle)
        mychart.addElement(mylegend)

        # Plot area
        plotstyle = Style(name="plotstyle", family="chart")
        plotstyle.addElement(
            ChartProperties(seriessource="columns",
                            percentage="false",
                            stacked="false",
                            threedimensional="true"))
        doc.automaticstyles.addElement(plotstyle)

        plotarea = chart.PlotArea(datasourcehaslabels="both",
                                  stylename=plotstyle)
        mychart.addElement(plotarea)

        # Style for the X,Y axes
        axisstyle = Style(name="axisstyle", family="chart")
        axisstyle.addElement(ChartProperties(displaylabel="true"))
        doc.automaticstyles.addElement(axisstyle)

        # Title for the X axis
        xaxis = chart.Axis(dimension="x",
                           name="primary-x",
                           stylename=axisstyle)
        plotarea.addElement(xaxis)
        xt = chart.Title()
        xaxis.addElement(xt)
        xt.addElement(text.P(text="x_axis"))

        # Title for the Y axis
        yaxis = chart.Axis(dimension="y",
                           name="primary-y",
                           stylename=axisstyle)
        plotarea.addElement(yaxis)
        yt = chart.Title()
        yaxis.addElement(yt)
        yt.addElement(text.P(text="y_axis"))

        result = doc.contentxml()  # contentxml() is supposed to yeld a bytes
        self.assertNotEqual(-1, result.find(b'''style:family="chart"'''))
示例#5
0
        s = chart.Series(valuescellrangeaddress="local-table.C2:.C6",
                         labelcelladdress="local-table.C1")
        s.addElement(chart.DataPoint(repeated=5))
        plotarea.addElement(s)

        # The data are placed in a table inside the chart object - but could also be a
        # table in the main document
        datatable = DataTable(self.values)
        datatable.datasourcehaslabels = self.datasourcehaslabels
        mychart.addElement(datatable())


if __name__ == "__main__":
    # Create the subdocument
    chartdoc = OpenDocumentChart()
    mychart = BarChart()
    mychart.title = "SPECTRE"
    mychart.subtitle = "SPecial Executive for Counter-intelligence, Terrorism, Revenge and Extortion"
    mychart.x_axis = "Divisions"
    mychart.y_axis = u"€ (thousand)"
    # These represent the data. Six rows in three columns
    mychart.values = (('', 'Expense', 'Revenue'), ('Counterfeit', 1000, 1500),
                      ('Murder', 1100, 1150), ('Prostitution', 3200, 2350),
                      ('Blackmail', 1100, 1150), ('Larceny', 1000, 1750))
    mychart.datasourcehaslabels = "both"
    mychart(chartdoc)

    # Create the containg document
    textdoc = OpenDocumentText()
    # Create a paragraph to contain the frame. You can put the frame directly