Click here to Skip to main content
14,766,373 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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.


https://freeimage.host/i/2AeUhu

https://ibb.co/2St6W4b


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[2].Points.Count;
     }


     foreach (var annotation in chart1.Annotations)
     {
         if (double.IsNaN(chart1.ChartAreas[sel_ChartAreaName].AxisX.ScaleView.Size))
         {
             annotation.Width = (annotation.Width * lastScaleViewSize) / chart1.Series[2].Points.Count;
         }
         else
         {
             annotation.Width = (annotation.Width * lastScaleViewSize) / chart1.ChartAreas[sel_ChartAreaName].AxisX.ScaleView.Size;
         }
     }


     lastScaleViewSize = chart1.ChartAreas[sel_ChartAreaName].AxisX.ScaleView.Size;
 }
Posted
Updated 21-Sep-20 20:15pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900