Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the direction of X-axis label in ms charts

Hi I am using Ms chart control in winforms application for displaying values according to dates

I need to change the x-axis label values(Dates) direction horizantal to vertical

I have searched so many properties but i did not find any solution for this.

Any one help me on this problem

enter image description here

Many Thanks ....

like image 418
user682417 Avatar asked Jul 18 '11 20:07

user682417


People also ask

How do you change the X-axis on a chart?

Right-click the X-axis in the chart you want to change. That will allow you to edit the X-axis specifically. Then, click on Select Data. Select Edit right below the Horizontal Axis Labels tab.


2 Answers

As I understand your question - you are asking how to rotate the chart label to display vertically.

You can rotate the x-axis label as follows:

chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -90;

This assumes you have associated your series with the first chart area, which is the default without modification when using the Winforms designer.

The following images shows how the chart would look before the code above is applied, the second image shows how it appears after the code is applied.

Let me know if this is not what you are trying to do and I will post an updated answer.

Before rotation
Before Rotation

After Rotation
enter image description here

Edit: Another answer added after my initial post mentions in certain situations it may be important to set chartArea1.AxisX.IsLabelAutoFit = false;

like image 79
JHubbard80 Avatar answered Sep 25 '22 14:09

JHubbard80


If you have not already done so, get the chart samples from microsoft:
http://archive.msdn.microsoft.com/mschart

Then check the section on Labels
Chart Features > Labels

To answer your question directly, set the angle in LabelStyle, and don't forget to disable autofit

chartArea1.AxisX.IsLabelAutoFit = false;
chartArea1.AxisX.LabelStyle.Angle = 90;
like image 38
zeFrenchy Avatar answered Sep 24 '22 14:09

zeFrenchy