如何为报表添加图表chart

 
 ExtendedItemHandle extendedItemHandle = elementFactory.newExtendedItem(null, "Chart"); 
 			extendedItemHandle.setHeight( "288pt" ); 
 			extendedItemHandle.setWidth( "252pt" ); 
 			extendedItemHandle.setProperty( ExtendedItemHandle.DATA_SET_PROP, "Data Set" ); 
 			// Add chart instance to IReportItem
 			extendedItemHandle.getReportItem( ).setProperty( "chart.instance", ChartUtil.createPieChart( ) );
 			designHandle.getBody().add(extendedItemHandle); 



调用方法创建图表
public static Chart createPieChart() {
		ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create();
		cwoaPie.setDimension(ChartDimension.TWO_DIMENSIONAL_WITH_DEPTH_LITERAL);
		cwoaPie.setType("Pie Chart"); //$NON-NLS-1$    
		cwoaPie.setSubType("Standard Pie Chart"); //$NON-NLS-1$

		// Plot
		cwoaPie.setSeriesThickness(10);

		// Legend
		Legend lg = cwoaPie.getLegend();
		lg.getOutline().setVisible(true);

		// Title
		cwoaPie.getTitle().getLabel().getCaption().setValue("Pie Chart");//$NON-NLS-1$

		// Data Set
		TextDataSet categoryValues = TextDataSetImpl
				.create(new String[] {
						"New York", "Boston", "Chicago", "San Francisco", "Dallas", "cs" });//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
		NumberDataSet seriesOneValues = NumberDataSetImpl.create(new double[] {
				54.65, 21, 75.95, 91.28, 37.43, 2.2 });

		SampleData sdata = DataFactory.eINSTANCE.createSampleData();
		BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData();
		sdBase.setDataSetRepresentation("");//$NON-NLS-1$
		sdata.getBaseSampleData().add(sdBase);

		OrthogonalSampleData sdOrthogonal = DataFactory.eINSTANCE
				.createOrthogonalSampleData();
		sdOrthogonal.setDataSetRepresentation("");//$NON-NLS-1$
		sdOrthogonal.setSeriesDefinitionIndex(0);
		sdata.getOrthogonalSampleData().add(sdOrthogonal);

		cwoaPie.setSampleData(sdata);

		// Base Series
		Series seCategory = SeriesImpl.create();
		seCategory.setDataSet(categoryValues);

		SeriesDefinition sd = SeriesDefinitionImpl.create();
		cwoaPie.getSeriesDefinitions().add(sd);
		// sd.getSeriesPalette( ).shift( 0 );
		final Fill[] fiaBase = {
				ColorDefinitionImpl.create(45, 150, 225),
				ColorDefinitionImpl.ORANGE(),
				ColorDefinitionImpl.CREAM(),
				ColorDefinitionImpl.RED(),
				ColorDefinitionImpl.GREEN(),
				GradientImpl.create(ColorDefinitionImpl.create(225, 225, 255),
						ColorDefinitionImpl.create(255, 255, 225), -35, false),
				ColorDefinitionImpl.CYAN().darker(), };
		sd.getSeriesPalette().getEntries().clear();
		for (int i = 0; i < fiaBase.length; i++) {
			sd.getSeriesPalette().getEntries().add(fiaBase[i]);
		}

		sd.getSeriesPalette().getEntries();
		sd.getSeries().add(seCategory);

		// Orthogonal Series
		PieSeries sePie = (PieSeries) PieSeriesImpl.create();
		sePie.setDataSet(seriesOneValues);
		sePie.setSeriesIdentifier("Cities");//$NON-NLS-1$ 
		sePie.setExplosion(5);

		SeriesDefinition sdCity = SeriesDefinitionImpl.create();
		sd.getSeriesDefinitions().add(sdCity);
		sdCity.getSeries().add(sePie);

		return cwoaPie;
	}
	

你可能感兴趣的:(chart)