[英]C# Windows Forms Chart Always Display Zero in YAxis
I draw some charts using DataVisualization.Charting.Chart
.我使用
DataVisualization.Charting.Chart
绘制了一些图表。 All of my charts have inverse Y range.我所有的图表都有反 Y 范围。
For Example "-20 to 20" or "-150 to 150".例如“-20 到 20”或“-150 到 150”。 It means that Zero is always in the middle of Y range, there is no problem in drawing but the chart never makes a label for Zero.
这意味着零总是在Y范围的中间,绘制没有问题但图表从来没有为零做标签。
For Example I have this labels -20,-15,-10,-5,5,10,15,20
.例如,我有这个标签
-20,-15,-10,-5,5,10,15,20
。 I always want to see the Zero in Y axis labels.我总是想看到 Y 轴标签中的零。 See the image:
看图:
I did it using CustomLabels
:我使用
CustomLabels
做到了:
int maxRange = 20;
int yInterval = 5;
var minRange = (maxRange * -1);
area.AxisY.Minimum = minRange;
area.AxisY.Maximum = maxRange;
area.AxisY.LabelStyle.Format = "#";
area.AxisY.Interval = yInterval;
int yVal = minRange;
while (yVal <= maxRange)
{
area.AxisY.CustomLabels.Add(yVal - 0.5, yVal + 0.5, yVal.ToString());
yVal += yInterval;
}
for this min & max must in 10s series对于这个最小和最大必须在 10s 系列
chart.ChartAreas[0].AxisX.Interval = 10;
chart.ChartAreas[0].AxisY.Interval = 10;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.