how to set legend width

Thread is closed for posting
3 posts, 1 answers
  1. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 19 May 2011 Link to this post


    I have long series names in a legend so I have set AutoTextWrap = true, but they wrap too much!
    1 of the series names is wrapping over 3 lines instead of 2 lines, so I thought I'd make the legend box wider to accomodate it, but it ignores everything I've tried. I've attached a pic.
    These lines do nothing:
    • RadChart1.Legend.Appearance.Dimensions.Width = new Telerik.Charting.Styles.Unit(50);
    • RadChart1.Legend.Appearance.ItemTextAppearance.Dimensions.Width = new Telerik.Charting.Styles.Unit(150);
    while this line makes the legend disappear:
    • RadChart1.Legend.Appearance.Dimensions.AutoSize = false;

    Here is the markup:
    <telerik:RadChart ID="RadChart1" runat="server"

    and here is the relevant code behind:
    RadChart1.Chart.Appearance.Border.Visible = false;
    RadChart1.Appearance.TextQuality = Telerik.Charting.Styles.TextQuality.ClearTypeGridFit;
    RadChart1.PlotArea.Appearance.FillStyle.FillType = Telerik.Charting.Styles.FillType.Solid;
    RadChart1.PlotArea.Appearance.FillStyle.MainColor = Color.White;
    RadChart1.PlotArea.Appearance.Border.Color = Color.LightGray;
    RadChart1.PlotArea.Appearance.Dimensions.Margins.Top = new Telerik.Charting.Styles.Unit(5);
    RadChart1.PlotArea.Appearance.Dimensions.Margins.Right = new Telerik.Charting.Styles.Unit(200);
    RadChart1.PlotArea.Appearance.Dimensions.Margins.Left = new Telerik.Charting.Styles.Unit(90);
    RadChart1.PlotArea.Appearance.Dimensions.Margins.Bottom = new Telerik.Charting.Styles.Unit(60);
    RadChart1.Legend.Appearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.TopRight;
    RadChart1.Legend.Appearance.ItemTextAppearance.AutoTextWrap = Telerik.Charting.Styles.AutoTextWrap.True;
    RadChart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate;
    RadChart1.PlotArea.XAxis.Appearance.CustomFormat = "d MMM";
    RadChart1.PlotArea.XAxis.DataLabelsColumn = "SHIFT_DATE";
    RadChart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = Color.Black;
    RadChart1.PlotArea.XAxis.LayoutMode = Telerik.Charting.Styles.ChartAxisLayoutMode.Normal;
    RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.Dimensions.Margins.Top = new Telerik.Charting.Styles.Unit(5);
    RadChart1.PlotArea.XAxis.IsZeroBased = false;
    RadChart1.PlotArea.XAxis.AddRange(startdate.ToOADate(), enddate.ToOADate(), 1);
    RadChart1.PlotArea.XAxis.LabelStep = Convert.ToInt32(Math.Floor(Convert.ToDecimal((enddate - startdate).Days / 8)));
    RadChart1.PlotArea.YAxis.Appearance.MajorGridLines.Visible = true;
    RadChart1.PlotArea.YAxis.Appearance.MajorGridLines.Color = Color.Gray;
    RadChart1.PlotArea.YAxis.IsZeroBased = true;
    RadChart1.PlotArea.YAxis.AxisLabel.TextBlock.Text = "Metres (RC)";
    RadChart1.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = Color.Black;
    RadChart1.PlotArea.YAxis.AxisLabel.Visible = true;
    RadChart1.PlotArea.YAxis.Appearance.CustomFormat = "N0";
    RadChart1.PlotArea.YAxis.Appearance.TextAppearance.TextProperties.Color = Color.Black;
    RadChart1.PlotArea.YAxis2.IsZeroBased = true;
    RadChart1.PlotArea.YAxis2.AxisLabel.TextBlock.Text = "m / day";
    RadChart1.PlotArea.YAxis2.AxisLabel.TextBlock.Appearance.TextProperties.Color = Color.Black;
    RadChart1.PlotArea.YAxis2.AxisLabel.Visible = true;
    RadChart1.PlotArea.YAxis2.Appearance.CustomFormat = "N0";
    RadChart1.PlotArea.YAxis2.Appearance.TextAppearance.TextProperties.Color = Color.Black;
    RadChart1.PlotArea.YAxis2.AxisLabel.Appearance.Position.AlignedPosition = Telerik.Charting.Styles.AlignedPositions.Left;

    What am I doing wrong?
  2. Answer
    Evgenia avatar
    1396 posts

    Posted 20 May 2011 Link to this post

    Hi Jeremy,
    • You can't change the legend dimensions or itemtextappearance without having the Legend.Appearance.Dimensions.AutoSize property set to False.
    • On the other hand when you are turning off this property you should define your own Height and Width for the Legend, otherwise they will be 0.

    There are also another important things you should mind:
    1. If you are using a Skin different than the Default one you should set the SkinsOverrideStyles property of the Chart to false. This way the Skin won't override the changes you are making.
    2. You can use the TextQuality property of the control to improve the readability of the Labels. For example you can set it to AntiAlias like this:

    RadChart1.Appearance.TextQuality = Telerik.Charting.Styles.TextQuality.AntiAlias;

    All the best,
    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. DevCraft R3 2016 release webinar banner
  4. Jeremy
    Jeremy avatar
    96 posts
    Member since:
    Mar 2010

    Posted 23 May 2011 Link to this post

    Ahah! Setting the height was what I was missing. Thanks!
Back to Top