1457726 - How to change Chart Object title text in .NET application

SAP Knowledge Base Article - Public

1457726 - How to change Chart Object title text in .NET application

Symptom

How to cahnge the Chart Title text and and font at runtime in a .NET application

Environment

Crystal Reports 2008 Service Pack 2

Visual Studio .NET 2005

Visual Studio .NET 2008

Cause

API Functions did not exist previously

Entered as an Enhancement Request

Resolution

API's are now available:


using System.Drawing;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;
using ReportObjects = CrystalDecisions.ReportAppServer.ReportDefModel.ReportObjects;
using IChartObject = CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject;
using IChartDefinition = CrystalDecisions.ReportAppServer.ReportDefModel.ChartDefinition;
using ChartObject = CrystalDecisions.ReportAppServer.ReportDefModel.ChartObjectClass;
using ChartStyle = CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyleClass;
using ChartStyleType = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartStyleTypeEnum;
using IChartTextOptions = CrystalDecisions.ReportAppServer.ReportDefModel.ChartTextOptions;
using IReportObject = CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject;
using IFontColor = CrystalDecisions.ReportAppServer.ReportDefModel.FontColor;
using IChartStyle = CrystalDecisions.ReportAppServer.ReportDefModel.ISCRChartStyle;
using IFont = CrystalDecisions.ReportAppServer.ReportDefModel.Font;


namespace EROMTestApp
{
    class Program
    {
        static void Main(string[] args)
        {
        
            ReportClientDocument rptClient = new ReportClientDocumentClass();
            String rptName = "..\\..\\chart_jdbc.rpt";
            object rptObject = (object)rptName;
            rptClient.ReportAppServer = "inproc:multithreaded";
            rptClient.Open(ref rptObject, 1);

            if (rptClient != null)
            {
                Console.WriteLine("Report is opened");
                
                ReportObjects chartObjs = rptClient.ReportDefController.QueryChartObjects();
                IChartObject thechart = (IChartObject)chartObjs[0];
                IChartObject thechart_new = (IChartObject)thechart.Clone(true);
                IChartTextOptions textOpts = thechart_new.ChartStyle.TextOptions;

                Console.WriteLine("textOpts.Title:" + textOpts.Title);
                Console.WriteLine("textOpts.GroupTitle:" + textOpts.GroupTitle);
                Console.WriteLine("textOpts.DataTitle:" + textOpts.DataTitle);
                Console.WriteLine("textOpts.Subtitle:" + textOpts.Subtitle);
                Console.WriteLine("textOpts.SeriesTitle:" + textOpts.SeriesTitle);
                Console.WriteLine("textOpts.Footnote:" + textOpts.Footnote);

                textOpts.Title = "Title update by jli";
                textOpts.Subtitle = "Subtitle update by jli";
                textOpts.DataTitle = "DataTitle update by jli";
                textOpts.GroupTitle = "GroupTitle update by jli";
                textOpts.SeriesTitle = "SeriesTitle update by jli";
                textOpts.Footnote = "Footnote update by jli";
               
                IFontColor fontColor = textOpts.GroupLabelFont;            
                IFont font = fontColor.Font;
                font.Underline = true;
                fontColor.Color = System.Convert.ToUInt32(ColorTranslator.ToWin32(System.Drawing.Color.Blue));
           
                textOpts.GroupLabelFont=fontColor;
                textOpts.DataLabelFont = fontColor;
                textOpts.DataTitleFont = fontColor;
                textOpts.FootnoteFont = fontColor;
                textOpts.GroupTitleFont = fontColor;
                textOpts.SeriesLabelFont = fontColor;
                textOpts.SubtitleFont = fontColor;
                textOpts.TitleFont = fontColor;
               
                rptClient.ReportDefController.ModifyChartObject(thechart, thechart_new);
                rptClient.Save();
                    // Close the report
                rptClient.Close();
            }           
        }
    }
}

Keywords

Chart Title text, Chart Title Font , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

Crystal Reports 2008 V1