当我按轴X滚动时,我的图表正在移动。我认为这是因为我使用自定义标签。如何修复axisX宽度?
chart1.ChartAreas[0].AxisX.IsMarksNextToAxis = false;
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = false;
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(1, 250);
chart1.ChartAreas[0].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.None;
chart1.ChartAreas[0].AxisX.IsLabelAutoFit = true;
chart1.ChartAreas[0].AxisY.LabelAutoFitStyle = LabelAutoFitStyles.None;
chart1.ChartAreas[0].AxisY.IsLabelAutoFit = false;
//custom labels
//...
//...
if (i % 13 == 0)
{
CustomLabel CL = new CustomLabel();
CL.FromPosition = i - 13;
CL.ToPosition = i + 13;
CL.Text = L[i].Item1.ToString("d MMM\r\nHH:mm");//+"\n"+L[i].Item1.ToString("HH:mm");
chart1.ChartAreas[0].AxisX.CustomLabels.Add(CL);
}
//...
//..
答案 0 :(得分:3)
大多数(如果不是全部)图表元素都具有某种大小属性。在您的情况下,您可以使用InnerPlotPosition
的{{1}}属性。有关详细信息,请参阅MSDN,但它可能类似于:
ChartArea
或者您可以执行以下操作:
chart1.ChartAreas[0].InnerPlotPosition.Width = 75; // this will make the plotting area width 75% of the whole chart area width
chart1.ChartAreas[0].InnerPlotPosition.Height = 60; // this makes the plotting area height 60% of the chart area height
可以同时设置绘图区域的位置和大小。
此属性需要注意的一点是,尺寸不是实际的像素大小,而是chart1.ChartAreas[0].InnerPlotPosition = new ElementPosition(5, 10, 75, 60);
大小的百分比。它需要大量的摆弄和反复试验才能使它们正确,并且在某些情况下您可能需要处理ChartArea
的{{1}}事件,以便在窗口获得时保持图表正常调整大小。
答案 1 :(得分:2)
问题可能是由于最右边的标签在滚动过程中出现和消失。如果是这样,您可以将ChartAreas[n].AxisX.LabelStyle.IsEndLabelVisible
设置为false来禁用它。这样你就不需要用InnerPlotPosition值来对抗。