It works out that when using the autofit of axis labels, the label values take on unappealing values. Has anyone developed code to evaluate range and scale of axis values and then show for example label values at intervals of 1, 5, 10, 20, etc? The syntax I am using is listed below:
它的工作原理是,当使用轴标签的autofit时,标签值会呈现出不吸引人的值。是否有人开发了代码来评估轴值的范围和规模,然后以1、5、10、20等的间隔显示示例标签值?我使用的语法如下所示:
Chart1.Series.Clear()
Chart1.ChartAreas("ChartArea1").AxisX.MajorGrid.Enabled = False
Chart1.ChartAreas("ChartArea1").AxisY.MajorGrid.Enabled = False
Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.Format = "N2"
Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Format = "N2"
Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Angle = 0
Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Enabled = True
Chart1.ChartAreas("ChartArea1").AxisX.IsLabelAutoFit = True
Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 12.0F, System.Drawing.FontStyle.Bold)
Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 12.0F, System.Drawing.FontStyle.Bold)
Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.IsEndLabelVisible = True
2 个解决方案
#1
1
RESOLVED: I discovered that if you use the floor and ceiling functions on xmin and xmax, and set intervalautomode=True, then the last right label will typically be displayed, and the labels will appear better. The floor and ceiling prevent label values of -2.3, 5.7, etc.
解析:我发现,如果您使用xmin和xmax上的地板和天花板的功能,并设置intervalauto =True,那么通常会显示最后一个正确的标签,并且标签看起来会更好。地板和天花板防止标签值为-2.3,5.7,等等。
Dim xmin, xmax As Double
xmin = 1.0E+30
xmax = -1.0E+30
For i = 1 To 1000
If x(i) < xmin Then xmin = x(i)
If x(i) > xmax Then xmax = x(i)
Next
Chart1.ChartAreas(0).AxisX.Minimum = Math.Floor(xmin)
Chart1.ChartAreas(0).AxisX.Maximum = Math.Ceiling(xmax)
Chart1.ChartAreas(0).AxisX.IntervalAutoMode = True
Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "N1"
For i = 1 To 1000
Chart1.Series(0).Points.AddXY(x(i), y(i))
Next
You would need to do more work if the range of x is less than 1, for example 0.02 to 0.85, or 0.0002 to 0.005, etc. since the floor and ceiling always round down to the next lower integer and round right to the next greatest integer.
如果x的范围小于1,则需要做更多的工作,例如0.02到0.85,或者0.0002到0.005,等等,因为地板和天花板一直都是向下的整数,然后是下一个最大整数的整数。
#2
0
You need to set AxisX.Minimum
and AxisX.Interval
.
你需要设置AxisX。最小和AxisX.Interval。
Chart1.ChartAreas(0).AxisX.Minimum = 0
Chart1.ChartAreas(0).AxisX.Interval = 1
Chart1.ChartAreas(0).AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount
You can set AxisX.Minimum
according to Series.Points(0).XValue
if you want.
你可以设置AxisX。据Series.Points最低(0)。XValue如果你想要的。
Chart1.ChartAreas(0).AxisX.Minimum = Math.Floor(Chart1.Series(0).Points(0).XValue / 5) * 5
Chart1.ChartAreas(0).AxisX.Interval = 5
#1
1
RESOLVED: I discovered that if you use the floor and ceiling functions on xmin and xmax, and set intervalautomode=True, then the last right label will typically be displayed, and the labels will appear better. The floor and ceiling prevent label values of -2.3, 5.7, etc.
解析:我发现,如果您使用xmin和xmax上的地板和天花板的功能,并设置intervalauto =True,那么通常会显示最后一个正确的标签,并且标签看起来会更好。地板和天花板防止标签值为-2.3,5.7,等等。
Dim xmin, xmax As Double
xmin = 1.0E+30
xmax = -1.0E+30
For i = 1 To 1000
If x(i) < xmin Then xmin = x(i)
If x(i) > xmax Then xmax = x(i)
Next
Chart1.ChartAreas(0).AxisX.Minimum = Math.Floor(xmin)
Chart1.ChartAreas(0).AxisX.Maximum = Math.Ceiling(xmax)
Chart1.ChartAreas(0).AxisX.IntervalAutoMode = True
Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "N1"
For i = 1 To 1000
Chart1.Series(0).Points.AddXY(x(i), y(i))
Next
You would need to do more work if the range of x is less than 1, for example 0.02 to 0.85, or 0.0002 to 0.005, etc. since the floor and ceiling always round down to the next lower integer and round right to the next greatest integer.
如果x的范围小于1,则需要做更多的工作,例如0.02到0.85,或者0.0002到0.005,等等,因为地板和天花板一直都是向下的整数,然后是下一个最大整数的整数。
#2
0
You need to set AxisX.Minimum
and AxisX.Interval
.
你需要设置AxisX。最小和AxisX.Interval。
Chart1.ChartAreas(0).AxisX.Minimum = 0
Chart1.ChartAreas(0).AxisX.Interval = 1
Chart1.ChartAreas(0).AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount
You can set AxisX.Minimum
according to Series.Points(0).XValue
if you want.
你可以设置AxisX。据Series.Points最低(0)。XValue如果你想要的。
Chart1.ChartAreas(0).AxisX.Minimum = Math.Floor(Chart1.Series(0).Points(0).XValue / 5) * 5
Chart1.ChartAreas(0).AxisX.Interval = 5