Reputation: 15
when I scroll by axisX my chart is shifting. I think it happens because I use custom lablels. How to fix axisX width?
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);
}
//...
//..
Upvotes: 1
Views: 952
Reputation: 340
Probably the problem is caused by the right-most label appearing and disappearing during scrolling. If so you can disable it by setting ChartAreas[n].AxisX.LabelStyle.IsEndLabelVisible
to false. That way you don't need to fight with InnerPlotPosition values.
Upvotes: 3
Reputation: 1610
Most, if not all, chart elements have some sort of size property. In your case, you can use the InnerPlotPosition
property of the ChartArea
. See MSDN for more details, but it might look something like:
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
or you could do something like:
chart1.ChartAreas[0].InnerPlotPosition = new ElementPosition(5, 10, 75, 60);
which would set the location and size of the plotting area all at once.
One thing to note with this property is that the sizes are not actual pixel sizes, but percentages of the size of the ChartArea
. It takes a lot of fiddling and trial-and-error to get them right, and you may need to handle the Form
's Resize
event in some cases to keep the chart looking good when the window gets resized.
Upvotes: 3