X 轴和 Y 轴上的 Windows 窗体 C# 图形轴标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10331455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Form C# Graph Axes Label on both X & Y axes
提问by dushyantp
Can anyone please tell me how to write the labels on the x-y-axes on the graph? The ones that say "Time(s)" & "Speed (m/s)".
谁能告诉我如何在图表的 xy 轴上写标签?那些说“时间(s)”和“速度(m / s)”的人。
I am using System.Windows.Forms.DataVisualization.Charting.Chart. There should be a simple property somewhere which I am missing or is it something more complicated?
我正在使用System.Windows.Forms.DataVisualization.Charting.Chart. 某处应该有一个我遗漏的简单属性还是更复杂的东西?


采纳答案by Philip Fourie
I am using the charts control on the web and setting the X and Y axis titles are done in the following way.
我正在使用网络上的图表控件,并通过以下方式设置 X 和 Y 轴标题。
I assume the API would be the same for winforms.
我认为 API 与 winforms 相同。
var chartArea = new ChartArea("MyChart");
...
chartArea.AxisX.Title = "Times(s)";
chartArea.AxisY.Title = "Speed (m/s)";
回答by Mytroy2050
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.
没有一个解决方案对我有用。我使用以下代码帮助我在 Windows 窗体图表上添加轴标题。我正在添加一些有用的属性,以便任何正在使用它的人都可以知道如何使用它。我搜索了很多以找出所有这些属性。这种类型的例子很少。
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

