This is probably the most wanted question I think if you are using the Dot Net Chart Control. I searched on many Q&A sites but I still have not find an answer.
I have about 6 to 7 chart areas alinged in one chart.
I allowed the horiozontal scale (i.e. zooming in X axis) of my chart.
I can add line and rectangle annotation dynamically in run time.
What is the robust way to rescale chart annotation when zooming in event is trigerred ?
I fixed InnerPlotPosition of my chart area like this for all of my chart to avoid any change in the width of inner plot area like this.
chartArea1.InnerPlotPosition.Auto = false;
chartArea1.InnerPlotPosition.X = 10;
chartArea1.InnerPlotPosition.Y = 2;
chartArea1.InnerPlotPosition.Height = 55;
chartArea1.InnerPlotPosition.Width = 90;
I use the below code to rescale all of my annotation in the chart.
Hence, the width of Inner Plot Area should be fixed. The scaling should not have the problem.
However, in practice, when I tried to zoom in, the drawn annotation is scaled but with some discrepancy. Sometimes, it is little bit smaller and sometimes it is little bit bigger.
You can check this behavour from the screenshot attached (Please let me know if you can not see the screenshot).
In the screenshot, I drawn the rectangle annotation in run time.
When it is zoomed in, the width of rectangle annotation is keep changing.
As far as I concern, there is no dynamically changing part in the chart area as I fixed the inner chart area.
What can cause this unstable behaviour and how can I fix this ?
Your help will be really appreciated.
What I have tried:
private double lastScaleViewSize = Double.NaN;
private void chart1_AxisViewChanged(object sender, ViewEventArgs e)
sel_ChartAreaName = e.ChartArea.Name;
if (Double.IsNaN(lastScaleViewSize) || lastScaleViewSize <= 0)
lastScaleViewSize = chart1.Series.Points.Count;
foreach (var annotation in chart1.Annotations)
annotation.Width = (annotation.Width * lastScaleViewSize) / chart1.Series.Points.Count;
annotation.Width = (annotation.Width * lastScaleViewSize) / chart1.ChartAreas[sel_ChartAreaName].AxisX.ScaleView.Size;
lastScaleViewSize = chart1.ChartAreas[sel_ChartAreaName].AxisX.ScaleView.Size;