Symptom
Reproducing the Issue
Resolution
sample code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportAppServer.ClientDoc;
ReportDocument m_boReportDocument;
ISCDReportClientDocument m_boReportClientDocument;
CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject m_boChartObject;
CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyle m_boChartStyle;
CrystalDecisions.ReportAppServer.ReportDefModel.Section m_boSection;
CrystalDecisions.ReportAppServer.DataDefModel.Fields m_boFields;
CrystalDecisions.ReportAppServer.DataDefModel.Field m_boField;
CrystalDecisions.ReportAppServer.DataDefModel.SummaryField m_boSummaryField;
int m_boFieldIndex;
//create a new ReportDocument
m_boReportDocument = new ReportDocument();
//load the RPT file
m_boReportDocument.Load("..\\..\\AddChart.rpt");
//access the ReportClientDocument in the ReportDocument (EROM bridge)
m_boReportClientDocument = m_boReportDocument.ReportClientDocument;
m_boFields = m_boReportClientDocument.DatabaseController.Database.Tables[0].DataFields;
//create a chart
m_boChartObject = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject();
//create a bar chart style
m_boChartStyle = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyle();
m_boChartStyle.Type = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartStyleTypeEnum.crChartStyleTypeBar;
//set the chart style to bar chart
m_boChartObject.ChartStyle = m_boChartStyle;
//set the chart type to advanced chart
m_boChartObject.ChartDefinition.ChartType = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartTypeEnum.crChartTypeDetail;
//set Customer Name field as condition field
//get the Customer Name field
m_boFieldIndex = m_boFields.Find("Customer Name",
CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
m_boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[m_boFieldIndex];
m_boChartObject.ChartDefinition.ConditionFields.Add(m_boField);
m_boField = null;
//set Last Year's Sales as data field
//get {Customer.Last Year's Sales field}
m_boFieldIndex = m_boFields.Find("Last Year's Sales",
CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
m_boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[m_boFieldIndex];
//create a Sum({Customer.Last Year's Sales})
m_boSummaryField = new CrystalDecisions.ReportAppServer.DataDefModel.SummaryField();
m_boSummaryField.SummarizedField = m_boField;
m_boSummaryField.Operation = CrystalDecisions.ReportAppServer.DataDefModel.CrSummaryOperationEnum.crSummaryOperationSum;
m_boSummaryField.Type = m_boField.Type;
//add summary field to report client document
m_boReportClientDocument.DataDefController.SummaryFieldController.Add(-1, m_boSummaryField);
m_boChartObject.ChartDefinition.DataFields.Add(m_boSummaryField);
//set chart coordinates and dimensions (0, 0), width = 7 inches, height = 5 inches
m_boChartObject.Left = 0;
m_boChartObject.Top = 0;
m_boChartObject.Width = 7 * 1440; // 1 inch = 1440 twips
m_boChartObject.Height = 5 * 1440;
//get report header section
m_boSection = m_boReportClientDocument.ReportDefinition.ReportHeaderArea.Sections[0];
//set chart report area to report header
m_boChartObject.ChartReportArea = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportHeader;
//add chart in the report header
m_boReportClientDocument.ReportDefController.ReportObjectController.Add(boChartObject, boSection, -1);
//display in reportviewer
crystalReportViewer1.ReportSource = m_boReportDocument;
Keywords
How add chart Crystal Reports inproc RAS .NET SDK , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To