Programmatically Add TextBlocks to ChartTitle?

Thread is closed for posting
6 posts, 0 answers
  1. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 03 Aug 2011 Link to this post

    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);
  2. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 08 Aug 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 08 Aug 2011 Link to this post

    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?
  5. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 10 Aug 2011 Link to this post

    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.

  6. Jorge Gracia
    Jorge Gracia avatar
    6 posts
    Member since:
    Nov 2009

    Posted 30 Nov 2011 Link to this post

    Unfortunally the suggested demo does not specify how to make the label split onto multi-lines.
  7. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 05 Dec 2011 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017