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
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.
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.
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