11.3.3.2. Pie Chart Template Script

The following snippet shows how to display the data that was prepared by the Groovy script before.

  <p:paragraph horizontalAlignment="center">
    <p:piechart title="Testresults" direction="anticlockwise" circular="true"
      startAngle="30" labelGap="0.1" labelLinkPaint="black" plotBackgroundPaint="white"
      labelBackgroundPaint="white" is3D="true">
      <p:series key="results">
        <p:data key="Error [#{error.size}]" value="#{error.size}" sectionPaint="#FF0A0A" />
        <p:data key="Success [#{success.size}]" value="#{success.size}" sectionPaint="#33CC00"/>
        <p:data key="Failure [#{failure.size}]" value="#{failure.size}" sectionPaint="#FFCC00"/>
      </p:series>
    </p:piechart>
  </p:paragraph>
	

The piechart element builds the frame for the chart by defining the main outlook of the chart. For detailed information on different charts please check the SeamPDF documentation. For a pie chart a series of data is required. The data is retrieved from the lists stored in the context by the Groovy script.

  <p:data key="Error [#{error.size}]" value="#{error.size}" sectionPaint="#FF0A0A" />
	

This code retrieves the list containing the error results from the context and calls its size() method to determine the amount of erroneous test cases. The pie chart is then rendered from the three data sections, as seen in Figure 11.8, “A Pie Chart Example” .