Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Detail Pie chart using Crystal Reports for eclipse

Hi,

I am using the following method to add pie chart to a report. the result i get is multiple pie instead of one pie, although the chart expert shows the proper input. The same code works fine for bar chart.

public static void AddChartDetail(ReportClientDocument clientDoc, String chartTitle, String gt) throws Exception

{

ChartDefinition chartDefinition = new ChartDefinition();

chartDefinition.setChartType(ChartType.detail);

IDataDefinition dataDefinition = clientDoc.getDataDefController().getDataDefinition();

Fields conditionFields = new Fields();

IField field = null;//dataDefinition.getGroups().getGroup(0).getConditionField();

field = clientDoc.getDatabaseController().getDatabase().getTables().findTableByAlias("MyTableName").getDataFields().findField("My Column Name", FieldDisplayNameType.fieldName, Locale.US);

conditionFields.addElement(field);

chartDefinition.setConditionFields(conditionFields);

SummaryField summaryField1 = new SummaryField();

summaryField1.setName("Hello");

summaryField1.setOperation(SummaryOperation.count);

summaryField1.setSummarizedField(clientDoc.getDatabaseController().getDatabase().getTables().findTableByAlias("My Another Table").getDataFields().findField("My Another Column", FieldDisplayNameType.fieldName, Locale.US));

Fields dataFields = new Fields();

dataFields.add(summaryField1);

/*

for (int i = 0; i < dataDefinition.getSummaryFields().size(); i++)

{

IField summaryField = dataDefinition.getSummaryFields().getField(i);

dataFields.addElement(summaryField);

System.out.println("Setting data field");

}

*/

chartDefinition.setDataFields(dataFields);

//chartDefinition.setGroups(arg0)

ChartObject chartObject = new ChartObject();

chartObject.setChartDefinition(chartDefinition);

ChartStyleType chartStyleType = ChartStyleType.bar;

if(gt != null && gt.equals("pie"))

chartStyleType = ChartStyleType.pie;

else if(gt != null && gt.equals("bar"))

chartStyleType = ChartStyleType.bar;

AreaSectionKind chartPlacement = AreaSectionKind.pageHeader;

chartObject.getChartStyle().setType(chartStyleType);

chartObject.setChartReportArea(chartPlacement);

chartObject.getChartStyle().getTextOptions().setTitle(chartTitle);

chartObject.setHeight(5000);

chartObject.setWidth(5000);

chartObject.setTop(1000);

IArea reportHeaderArea = clientDoc.getReportDefController().getReportDefinition().getReportHeaderArea();

Section chartSection =(Section)reportHeaderArea.getSections().getSection(0);

clientDoc.getReportDefController().getReportObjectController().add(chartObject, chartSection, 1);

}

Former Member
Not what you were looking for? View more on this topic or Ask a question