1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| private ExtendedItemHandle createPieChart() throws SemanticException {
ExtendedItemHandle eih = designFactory.newExtendedItem(null, "Chart");//$NON-NLS-1$
try {
//eih.setHeight("3");//$NON-NLS-1$
// eih.setWidth("5");//$NON-NLS-1$
eih.setProperty(ExtendedItemHandle.DATA_SET_PROP, "ChartData");//$NON-NLS-1$
} catch (SemanticException e) {
e.printStackTrace();
}
ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create();
cwoaPie.setType("Pie Chart");//$NON-NLS-1$
cwoaPie.setSubType("Standard Pie Chart");//$NON-NLS-1$
cwoaPie.getTitle().setVisible(false);
cwoaPie.getBlock().setBounds(BoundsImpl.create(0, 0, 252, 288));
cwoaPie.getBlock().getOutline().setVisible(true);
cwoaPie.getBlock().setBackground(
GradientImpl.create(ColorDefinitionImpl.create(204, 254, 204),
ColorDefinitionImpl.create(254, 226, 240), -35, false));
cwoaPie.getPlot().getClientArea().setBackground(
ColorDefinitionImpl.TRANSPARENT());
cwoaPie.getLegend().setBackground(ColorDefinitionImpl.TRANSPARENT());
cwoaPie.getLegend().getClientArea().setBackground(
ColorDefinitionImpl.TRANSPARENT());
SampleData sd = DataFactory.eINSTANCE.createSampleData();
BaseSampleData sdBase = DataFactory.eINSTANCE.createBaseSampleData();
sdBase.setDataSetRepresentation("Category-A, Category-B");//$NON-NLS-1$
sd.getBaseSampleData().add(sdBase);
OrthogonalSampleData sdOrthogonal = DataFactory.eINSTANCE
.createOrthogonalSampleData();
sdOrthogonal.setDataSetRepresentation("4,1");//$NON-NLS-1$
sdOrthogonal.setSeriesDefinitionIndex(0);
sd.getOrthogonalSampleData().add(sdOrthogonal);
cwoaPie.setSampleData(sd);
Series seCategory = SeriesImpl.create( );
Query query = QueryImpl.create("row[\"" + (String)cols[0] + "\"]");//$NON-NLS-1$
seCategory.getDataDefinition().add( query );
SeriesDefinition series = SeriesDefinitionImpl.create( );
series.getSeries( ).add( seCategory );
cwoaPie.getSeriesDefinitions( ).add( series );
PieSeries ps = (PieSeries) PieSeriesImpl.create( );
Query query2 = QueryImpl.create( "row[\"" + (String)cols[1] + "\"]" );//$NON-NLS-1$
ps.getDataDefinition( ).add( query2 );
DataPointComponent dpc = DataPointComponentImpl.create(
DataPointComponentType.ORTHOGONAL_VALUE_LITERAL,
JavaNumberFormatSpecifierImpl.create("###,###"));//$NON-NLS-1$
ps.getDataPoint().getComponents().clear();
ps.getDataPoint().getComponents().add(dpc);
ps.getLabel().setVisible(true);
ChartReportItemImpl crii;
try {
// Add ChartReportItemImpl to ExtendedItemHandle
crii = (ChartReportItemImpl) eih.getReportItem();
// Add chart instance to ChartReportItemImpl
crii.setProperty("chart.instance", cwoaPie);//$NON-NLS-1$
} catch (ExtendedElementException e) {
e.printStackTrace();
}
return eih;
} |
Partager