Add axis name into chart c#

天涯浪子 提交于 2021-02-16 14:31:25

问题


I'm working with winforms using C#.

I use chart and I want to set the titles of the X- and Y-axis in code. I tried

chart1.chartarea(0).axisX.title = "xxx" 

but it does't work and I don't know why.


回答1:


I am using the charts control on the web and setting the X and Y axis titles are done in the following way.

I assume the API would be the same for winforms.

var chartArea = new ChartArea("MyChart");
...
chartArea.AxisX.Title = "xxx";
chartArea.AxisY.Title = "yyy";



回答2:


None of the solutions worked for me. I used the following code which helped me to add Axis title on windows form chart. I am adding a couple of useful properties so anyone who is working on it can have an idea how to use it. I searched a lot to find out all those properties. There are very few examples of this types.

chartESTOr.Titles.Add("Est OR Date " + " (" + Year + ")").Font = new Font("Arial", 10, FontStyle.Bold); // Chart Title
chartESTOr.ChartAreas["ChartArea1"].AxisX.Title = "Month";  // Chart X Axis Title
chartESTOr.ChartAreas["ChartArea1"].AxisX.TitleAlignment = StringAlignment.Center; // Chart X axis Text Alignment 
chartESTOr.ChartAreas["ChartArea1"].AxisX.TextOrientation = TextOrientation.Rotated270; // Chart X Axis Text Orientation 
chartESTOr.ChartAreas["ChartArea1"].AxisX.TitleFont = new Font("Arial", 8, FontStyle.Bold); // Chart X axis Title Font
chartESTOr.ChartAreas["ChartArea1"].AxisX.Interval = 1; // Chart X Axis Interval
chartESTOr.ChartAreas["ChartArea1"].AxisY.Title = "Quote Value (USD)"; // Chart Y Axis Title 
chartESTOr.ChartAreas["ChartArea1"].AxisY.TitleAlignment = StringAlignment.Center;  // Chart Y axis Text Alignment 
chartESTOr.ChartAreas["ChartArea1"].AxisY.TextOrientation = TextOrientation.Horizontal; // Chart Y Axis Text Orientation
chartESTOr.ChartAreas["ChartArea1"].AxisY.TitleFont = new Font("Arial", 8, FontStyle.Bold); // Chart Y axis Title Font
chartESTOr.ChartAreas["ChartArea1"].AxisY.LabelStyle.Format = "{0:0,}K"; // Chart Y Axis lable format



回答3:


As suggested by @TaW in comments this code works as: chart1.ChartAreas[0].AxisX.Title = "xxx";



来源:https://stackoverflow.com/questions/29589905/add-axis-name-into-chart-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!