I guess I should have mentioned this is using JFreeChart.  ;-)

On Feb 5, 2006, at 3:25 PM, Mark Morris wrote:

Hello Amedeo,

Here's an example of a pie chart.  This method can be bound directly to the "data" binding of a WOImage.  (Of course, then it will regenerate each time the page is displayed.)  This is only an example, and don't worry about what an OPDataCategory does, just know we're setting the values in a DefaultPieDataset.

public NSData pieChart1() {
DefaultPieDataset result = new DefaultPieDataset();
Enumeration aCatEnum = ((Session)session()).pieChartCategories.objectEnumerator();
while( aCatEnum.hasMoreElements() ) {
  OPDataCategory aCat = (OPDataCategory)aCatEnum.nextElement();
           result.setValue( aCat.categoryName(),
      aCat.dataItemForTimePeriodAndType( (Integer)((Session)session()).pieChartPeriods.anyObject(),
  ((Session)session()).currentTimePeriodType ).dataItemValue() );
}
        
JFreeChart aChart = ChartFactory.createPieChart(
            "Comparison",  // chart title
            result,                // data
            true,                   // include legend
            true,
            false
        );
        final PiePlot plot = (PiePlot) aChart.getPlot();
        plot.setNoDataMessage("No data available");
plot.setSectionPaint( 0, Color.green );

    ByteArrayOutputStream myByteStream = new ByteArrayOutputStream();

        try {
  ChartUtilities.writeChartAsJPEG( myByteStream, aChart, 680, 430 );
} catch (Exception e) {
  NSLog.err.appendln( "ChartsPage: pieChart1: Error: " + e.toString() );
}

        return new NSData( myByteStream.toByteArray() );
    }


Hope this helps.

Regards,
Mark

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to