C# 滚动时图表宽度的变化

C# 滚动时图表宽度的变化,c#,charts,C#,Charts,当我通过axisX滚动时,我的图表正在移动。我想这是因为我使用自定义标签。如何固定axisX宽度 chart1.ChartAreas[0].AxisX.IsMarksNextToAxis = false; chart1.ChartAreas[0].CursorX.IsUserEnabled = true; chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;

当我通过axisX滚动时,我的图表正在移动。我想这是因为我使用自定义标签。如何固定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);
                 }
              //...
              //..

大多数(如果不是全部的话)图表元素都有某种大小属性。在您的情况下,可以使用
图表区域
InnerPlotPosition
属性。有关更多详细信息,请参见,但它可能类似于:

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);
或者你可以这样做:

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);
这将同时设置打印区域的位置和大小


此属性需要注意的一点是,大小不是实际的像素大小,而是
图表区域大小的百分比。要使它们正确,需要进行大量的修改和反复试验,在某些情况下,您可能需要处理
表单
调整大小
事件,以便在调整窗口大小时保持图表外观良好。

大多数(如果不是全部)图表元素都具有某种大小属性。在您的情况下,可以使用
图表区域
InnerPlotPosition
属性。有关更多详细信息,请参见,但它可能类似于:

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);
或者你可以这样做:

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);
这将同时设置打印区域的位置和大小


此属性需要注意的一点是,大小不是实际的像素大小,而是
图表区域大小的百分比。要使它们正确,需要大量的修改和反复试验,在某些情况下,您可能需要处理
表单
调整大小
事件,以便在调整窗口大小时保持图表的外观良好。

问题可能是由于滚动期间最右边的标签出现和消失造成的。如果是这样,您可以通过将
ChartAreas[n].AxisX.LabelStyle.IsEndLabelVisible
设置为false来禁用它。这样,您就不需要与InnerPlotPosition值发生冲突。

问题可能是由于最右边的标签在滚动过程中出现和消失造成的。如果是这样,您可以通过将
ChartAreas[n].AxisX.LabelStyle.IsEndLabelVisible
设置为false来禁用它。这样,您就不需要与InnerPlotPosition值发生冲突