RotationAngle set in code behind has no effect

Thread is closed for posting
7 posts, 0 answers
  1. Louise
    Louise avatar
    9 posts
    Member since:
    Oct 2012

    Posted 06 Feb 2013 Link to this post

    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.
  2. Missing user
    Missing user avatar

    Posted 11 Feb 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Louise
    Louise avatar
    9 posts
    Member since:
    Oct 2012

    Posted 13 Feb 2013 Link to this post

    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

  5. Missing user
    Missing user avatar

    Posted 18 Feb 2013 Link to this post

    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.
  6. Louise
    Louise avatar
    9 posts
    Member since:
    Oct 2012

    Posted 20 Feb 2013 Link to this post

    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?
  7. Missing user
    Missing user avatar

    Posted 21 Feb 2013 Link to this post

    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.
  8. Louise
    Louise avatar
    9 posts
    Member since:
    Oct 2012

    Posted 22 Feb 2013 Link to this post

    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

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017