为什么当我使用MS图表控件缩放时,x轴标签消失了?
本文关键字:标签 消失了 缩放 控件 MS 为什么 | 更新日期: 2023-09-27 18:14:57
我正在使用MS图表控件。折线图是一种普通的基于时间的图表。问题是,当我单击图表并选择某个时间时,它会放大,滚动条出现,x轴标签消失。我怎样才能避免这种情况的发生?如果我不能自动修复它,是否有代码我可以添加到一个按钮,将固定标签?
private void Chart0Configuration()
{
chart1.ChartAreas[0].Visible = false;
chart1.ChartAreas[0].AlignmentOrientation = AreaAlignmentOrientations.Vertical;
chart1.ChartAreas[0].AlignmentStyle = AreaAlignmentStyles.All;
chart1.ChartAreas[0].Position.Auto = false;
chart1.ChartAreas[0].Position.X = 2;
chart1.ChartAreas[0].Position.Y = 10;
chart1.ChartAreas[0].Position.Width = 98;
//chart1.ChartAreas[0].Position.Height = *****variable
//chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
//chart1.ChartAreas[0].AxisY.MinorTickMark.Enabled = false;
//chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
//chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = true;
//chart1.ChartAreas[0].AxisX.MinorTickMark.Enabled = true;
//chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
//chart1.ChartAreas[0].AxisX.MajorTickMark.Interval = 10;
chart1.ChartAreas[0].AxisX.Interval = 0;
chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
chart1.ChartAreas[0].AxisX.LabelStyle.Enabled = true;
//chart1.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm:ss";
chart1.ChartAreas[0].AxisY.LabelStyle.IsEndLabelVisible = true;
chart1.ChartAreas[0].InnerPlotPosition.Auto = false;
chart1.ChartAreas[0].InnerPlotPosition.X = 3;
chart1.ChartAreas[0].InnerPlotPosition.Y = 10;
chart1.ChartAreas[0].InnerPlotPosition.Width = 88;
chart1.ChartAreas[0].InnerPlotPosition.Height = 80;
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
//chart1.ChartAreas[0].CursorX.AutoScroll = true;
chart1.ChartAreas[0].CursorX.Position = 0;
chart1.ChartAreas[0].CursorX.Interval = 0;
chart1.ChartAreas[0].AxisX.ScrollBar.Size = 5;
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
chart1.ChartAreas[0].AxisX.ScrollBar.BackColor = Color.LightGray;
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonColor = Color.Gray;
chart1.ChartAreas[0].AxisX.ScrollBar.LineColor = Color.Black;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
}
我在查看间隔时无意中找到了答案。现在我添加了以下代码行,它们仍然可见。
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;