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

RotationAngle set in code behind has no effect

6 Answers 65 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Louise
Top achievements
Rank 1
Louise asked on 06 Feb 2013, 10:44 AM
I have a rad chart control created in the code behind. I set the rotation angle for the x-axis labels but it has no effect:

myChartControl.PlotArea.XAxis.AxisLabel.Appearance.RotationAngle = 45;

I have encountered this problem before and got around it by setting the RotationAngle in the ASPX code. In this case however, this is not possible.

6 Answers, 1 is accepted

Sort by
0
Missing User
answered on 11 Feb 2013, 11:49 AM
Hi Louise,

The problem you describe is one we're familiar with. Due to the nature of the ASP.NET framework, when you create a control from code-behind, you have to make sure that you add it to the Page.Controls collection immediately after instantiating it. The ASP.NET framework applies a viewstate to a control the moment it's added to Page.Controls and any changes to a control's state made between creating and adding it will be lost, if there's an existing viewstate for it in the web application. Therefore, I'd like to ask you to first check whether you add the RadChart before setting the RotationAngle property and if not whether doing so will solve the problem.

Kind regards,
Ivan N.
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.
0
Louise
Top achievements
Rank 1
answered on 13 Feb 2013, 09:13 AM
Hi,

The chart is being output onto a PDF. It is created as follows:

myChartControl = new RadChart();
...
myChartControl.PlotArea.XAxis.AxisLabel.Appearance.RotationAngle = 45;
...

System.Drawing.Image myChart = myChartControl.GetBitmap();
MemoryStream imageStream = new MemoryStream();
myChart.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageContent = new Byte[imageStream.Length];
imageStream.Position = 0;
imageStream.Read(imageContent, 0, (int)imageStream.Length);
Response.ContentType = "image/png";
Response.BinaryWrite(imageContent);

Thanks,

Louise

0
Missing User
answered on 18 Feb 2013, 11:36 AM
Hi Louise,

Thank you for clarifying the situation. While I was able to achieve a scenario similar to yours based on the code from your last post, I couldn't reproduce the issue. I've attached the project I was working on while trying to do so, as well as the image returned after running it.

Greetings,
Ivan N.
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.
0
Louise
Top achievements
Rank 1
answered on 20 Feb 2013, 08:36 AM
Hello, I don't seem to be able to open the rar file attached. Would it be possible for you to attach the project as a zip file?
0
Missing User
answered on 21 Feb 2013, 04:02 PM
Hi Louise,

I've reattached the project in a zip archive, as you requested.

Kind regards,
Ivan N.
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.
0
Louise
Top achievements
Rank 1
answered on 22 Feb 2013, 08:44 AM
Hello,

Thanks for the example project. The difference was in the syntax:

My code:

myChartControl.PlotArea.XAxis.AxisLabel.Appearance.RotationAngle = 45;

 
Your code:
myChartControl.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 45;

Your code works, the method called in mine does not seem to do anything.

One additional problem. Now that the labels rotate they do not display in full on the chart (I'm displaying dates so they are quite long). Is there a setting to change the amount of space below the chart so that the labels appear in full?
This can be demonstrated in your code by changing the following:

new ChartData { XCat = DateTime.Now.ToShortDateString(), YVal = 5 },

new ChartData { XCat = DateTime.Now.AddDays(1).ToShortDateString(), YVal = 7 },

new ChartData { XCat = DateTime.Now.AddDays(2).ToShortDateString(), YVal = 4 },

new ChartData { XCat = DateTime.Now.AddDays(3).ToShortDateString(), YVal = 3 },

new ChartData { XCat = DateTime.Now.AddDays(4).ToShortDateString(), YVal = 8 },


Thanks, Louise

Tags
Chart (Obsolete)
Asked by
Louise
Top achievements
Rank 1
Answers by
Missing User
Louise
Top achievements
Rank 1
Share this question
or