This is a migrated thread and some comments may be shown as answers.
how to set legend width
2 Answers 82 Views
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 19 May 2011, 09:03 AM
Hi

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"
     Height="500px"
     Width="1200px"
     SkinsOverrideStyles="false"      
     ChartTitle-Visible="false">
</telerik:RadChart>

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 Answers, 1 is accepted

Sort by
0
Accepted
Evgenia
Telerik team
answered on 20 May 2011, 02:15 PM
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,
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
Jeremy
Top achievements
Rank 1
answered on 23 May 2011, 05:10 AM
Ahah! Setting the height was what I was missing. Thanks!
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Jeremy
Top achievements
Rank 1
Share this question
or