AODL.Document.Content.Charts.ChartTitle.SetTitle C# (CSharp) Method

SetTitle() public method

set the title
public SetTitle ( string Title ) : void
Title string
return void
		public void SetTitle(string Title)
		{
			if (this.Content .Count!=0)			  
			{
				 for(int i=0 ;i<this.Content .Count;i++)
				    this.Content .RemoveAt(i);
			}
			Paragraph para = new Paragraph (this.Chart.Document );
			para.TextContent .Add (new SimpleText (this.Document ,Title));
			
			if (this.Chart .Document.IsLoadedFile&&!this.Chart .IsNewed)
			{
				XmlNode node = this.Chart .ChartDoc .ImportNode (para.Node,true );
				this.Node .AppendChild (node);
			}

			else
			{
				this.Content .Add (para);
			}
			
			
		}

Usage Example

        public void NewBasicChartThenSetTitle()
        {
            string expected="Basic Chart";
            SpreadsheetDocument doc = new SpreadsheetDocument();
            doc.New();
            Table table = new Table(doc, "tab1", "tab1");

            for (int i = 1; i <= 1; i++)
            {
                for (int j = 1; j <= 6; j++)
                {
                    Cell cell = table.CreateCell();
                    cell.OfficeValueType = "float";
                    Paragraph paragraph = new Paragraph(doc);
                    string text = (j + i - 1).ToString();
                    paragraph.TextContent.Add(new SimpleText(doc, text));
                    cell.Content.Add(paragraph);
                    cell.OfficeValueType = "string";
                    cell.OfficeValue = text;
                    table.InsertCellAt(i, j, cell);
                }
            }
            Chart basicChart = ChartBuilder.CreateChart(table, ChartTypes.line, "A4:F8");
            ChartTitle ct = new ChartTitle(basicChart);
            //ct.InitTitle();
            ct.SetTitle(expected);
            Assert.AreEqual(expected, ((Paragraph)ct.Content[0]).TextContent[0].Text);
            basicChart.ChartTitle = ct;
            IContent chartTitleContent = null;
            chartTitleContent=basicChart.Content.Find(o => o is ChartTitle);
            if (chartTitleContent == null)
            {
                foreach (IContent iContent in basicChart.Content)
                {
                    if (iContent is ChartTitle) chartTitleContent = iContent;
                }
            }
            Assert.AreEqual(expected, ((Paragraph)((ChartTitle)chartTitleContent).Content[0]).TextContent[0].Text);
            table.InsertChartAt("H2", basicChart);
            doc.TableCollection.Add(table);
            doc.SaveTo(Path.Combine(AARunMeFirstAndOnce.outPutFolder,"BasicChartWithTitlesetafterwards.ods"));
        }