如何在图表区域内显示 Y 轴标签
how to display Y axis labels inside chart area
我有一个时间轴,我想在图表区域内而不是在图表区域外显示我的 Y 轴标签
这是我的代码
Series newSeries = new Series("hkld");
newSeries.ChartType = SeriesChartType.Line;
newSeries.BorderWidth = 2;
newSeries.Color = Color.OrangeRed;
newSeries.XValueType = ChartVal
chart1.ChartAreas[0].AxisY.IsReversed = true;
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 2;
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = 1000000;
chart1.ChartAreas[0].AxisX.Interval = 200000; //major interval
chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 20000; //minor interval
chart1.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot;
chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
chart1.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisY.Interval = 2;
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "HH:mm:ss";
chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 2;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;
chart1.ChartAreas[0].AxisY.MinorGrid.IntervalType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 2;
chart1.ChartAreas[0].AxisY.MinorGrid.LineDashStyle = ChartDashStyle.Dash;
chart1.ChartAreas[0].BorderColor = Color.Black;
chart1.ChartAreas[0].BorderWidth = 3;
chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
chart1.ChartAreas[0].Position.X = 5;
chart1.ChartAreas[0].Position.Y = 5;
chart1.ChartAreas[0].Position.Width = 90;
chart1.ChartAreas[0].Position.Height = 90;
chart1.ChartAreas[0].InnerPlotPosition.Height = 100;
chart1.ChartAreas[0].InnerPlotPosition.Width = 80;
chart1.ChartAreas[0].InnerPlotPosition.X = 20;
chart1.ChartAreas[0].Position.Auto = false;
这是我的图表的图片:
这就是我想要实现的目标:
注意:我的图表是实时图表,所以时间值会随着时间的推移而更新和上升(动态轴)
我认为您不能移动标签,但可以随标签一起移动轴。为此,请为 AxisX.Crossing
设置一个合适的值。
MSDN:
Setting this property for a primary axis will determine where the
other primary axis crosses it, and similarly setting it for a
secondary axis will determine where the other secondary axis crosses
it. For example, setting the Crossing property of the primary X-axis
determines where the primary Y-axis will cross it.
Four modes can be used for the Crossing property of an axis:
"Auto", which means that the crossing value will be set to the minimum or maximum value for the relevant axis...
"Minimum", which means the crossing value of the axis will be its minimum value...
"Maximum", which means the crossing value of the axis will be its maximum value...
A specified double value that is between the minimum and maximum values for the relevant axis...
这会将它移动到最后一个数据点的 x 值:
Axixs ax = chart1.ChartAreas[0].AxisX;
ax.Crossing = mySeries.Points.Last().XValue;
如果你知道你的数据,你可以使用固定值..
我有一个时间轴,我想在图表区域内而不是在图表区域外显示我的 Y 轴标签
这是我的代码
Series newSeries = new Series("hkld");
newSeries.ChartType = SeriesChartType.Line;
newSeries.BorderWidth = 2;
newSeries.Color = Color.OrangeRed;
newSeries.XValueType = ChartVal
chart1.ChartAreas[0].AxisY.IsReversed = true;
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 2;
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = 1000000;
chart1.ChartAreas[0].AxisX.Interval = 200000; //major interval
chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 20000; //minor interval
chart1.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot;
chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
chart1.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisY.Interval = 2;
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "HH:mm:ss";
chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 2;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;
chart1.ChartAreas[0].AxisY.MinorGrid.IntervalType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 2;
chart1.ChartAreas[0].AxisY.MinorGrid.LineDashStyle = ChartDashStyle.Dash;
chart1.ChartAreas[0].BorderColor = Color.Black;
chart1.ChartAreas[0].BorderWidth = 3;
chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
chart1.ChartAreas[0].Position.X = 5;
chart1.ChartAreas[0].Position.Y = 5;
chart1.ChartAreas[0].Position.Width = 90;
chart1.ChartAreas[0].Position.Height = 90;
chart1.ChartAreas[0].InnerPlotPosition.Height = 100;
chart1.ChartAreas[0].InnerPlotPosition.Width = 80;
chart1.ChartAreas[0].InnerPlotPosition.X = 20;
chart1.ChartAreas[0].Position.Auto = false;
这是我的图表的图片:
这就是我想要实现的目标:
注意:我的图表是实时图表,所以时间值会随着时间的推移而更新和上升(动态轴)
我认为您不能移动标签,但可以随标签一起移动轴。为此,请为 AxisX.Crossing
设置一个合适的值。
MSDN:
Setting this property for a primary axis will determine where the other primary axis crosses it, and similarly setting it for a secondary axis will determine where the other secondary axis crosses it. For example, setting the Crossing property of the primary X-axis determines where the primary Y-axis will cross it.
Four modes can be used for the Crossing property of an axis:
"Auto", which means that the crossing value will be set to the minimum or maximum value for the relevant axis...
"Minimum", which means the crossing value of the axis will be its minimum value...
"Maximum", which means the crossing value of the axis will be its maximum value...
A specified double value that is between the minimum and maximum values for the relevant axis...
这会将它移动到最后一个数据点的 x 值:
Axixs ax = chart1.ChartAreas[0].AxisX;
ax.Crossing = mySeries.Points.Last().XValue;
如果你知道你的数据,你可以使用固定值..