This is a migrated thread and some comments may be shown as answers.

Programmatically Add TextBlocks to ChartTitle?

5 Answers 81 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Marbry
Top achievements
Rank 1
Marbry asked on 03 Aug 2011, 07:09 PM

Can we programatically add a TextBlock to a ChartTitle?

The reason is to display a multiline title, with a different style applied to each line so that I could display something like,

MAIN TITLE
Sub Title

Where the font size of "Sub Title" is smaller than "MAIN TITLE".  I tried declaring new textblocks separately, then adding them to a charttitle, but it gives me a null object error when creating the textblock like,

TextBlock newBlock1 = new TextBlock(chartName);

5 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 08 Aug 2011, 09:02 AM
Hi Marbry,

You can use our Multiline Labels feature to have your title on multi lines. However note that you can't control the formatting of each line separately and you can't assign new TextBlock to the Chart title.

Best wishes,
Evgenia
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Marbry
Top achievements
Rank 1
answered on 08 Aug 2011, 02:37 PM
So there's no way to apply separate styles to parts of a title?  The whole thing has to have all the same style attributes?
0
Evgenia
Telerik team
answered on 10 Aug 2011, 11:33 AM
Hi Marbry,

There is no way out-of-the-box to accomplish this. As a possible workaround - you may add a transparent TextBox over the PlotArea on the place where the Title is positioned and set the desired text for the second Title in it. This way you will ve able to style the two titles separately.

Greetings,
Evgenia
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jorge Gracia
Top achievements
Rank 1
answered on 30 Nov 2011, 08:56 PM
Unfortunally the suggested demo does not specify how to make the label split onto multi-lines.
0
Petar Marchev
Telerik team
answered on 05 Dec 2011, 03:07 PM
Hello Jorge,

Just use a new line to separate the text. For instance you can use this:
<TextBlock Text="This is first line.
This is on another line">
 
instead of this:
<TextBlock Text="This will appear as a single line.">

You can achieve this with C# code, too.
this.radChart1.ChartTitle.TextBlock.Text += "first line here" + System.Environment.NewLine + "second line here";

To be able to have different styles applied to each line you can try something like this.
this.radChart1.ChartTitle.TextBlock.Text = "Main Title";
var titleStyleClone = (Telerik.Charting.Styles.StyleTextBlock)(this.radChart1.ChartTitle.TextBlock.Appearance.Clone());
TextBlock textBlockChartTitleSub = new TextBlock(titleStyleClone);
textBlockChartTitleSub.Parent = this.radChart1.ChartTitle;
textBlockChartTitleSub.Text = "another chart title";
textBlockChartTitleSub.Appearance.TextProperties.Color = System.Drawing.Color.Blue;
textBlockChartTitleSub.Appearance.TextProperties.Font = new System.Drawing.Font("Verdana", 10);
textBlockChartTitleSub.Appearance.Position.Y += 30;
this.radChart1.ChartTitle.Add(textBlockChartTitleSub);

Hope this is of help.

Best wishes,
Petar Marchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Chart (Obsolete)
Asked by
Marbry
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Marbry
Top achievements
Rank 1
Jorge Gracia
Top achievements
Rank 1
Petar Marchev
Telerik team
Share this question
or