Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to implement charts with square grid lines. The pixel value of a delta in X need to be the same as a delta in Y. How do it? this apper to be really simple, but I didn't find exemples in c#. I tried it, but the values do not converge in a chart run time modified...

public void MakeSquare(Chart Target, int Target_Index)
       {
          //peltiertech.com/Excel/Charts/SquareGrid.html

           double Inner_Height, Inner_Width, Ymax, Ymin, Ydel, Xmax, Xmin, Xdel;
           double Xpixel, Ypixel;

           do
           {
           Inner_Height = Target.ChartAreas[Target_Index].InnerPlotPosition.Height/100 * Target.Size.Height;
           Inner_Width = Target.ChartAreas[Target_Index].InnerPlotPosition.Width/100 * Target.Size.Width;

           Ymax = Target.ChartAreas[Target_Index].AxisY.Maximum;
           Ymin = Target.ChartAreas[Target_Index].AxisY.Minimum;
           Ydel = Target.ChartAreas[Target_Index].AxisY.MajorTickMark.Interval;

           Xmax = Target.ChartAreas[Target_Index].AxisX.Maximum;
           Xmin = Target.ChartAreas[Target_Index].AxisX.Minimum;
           Xdel = Target.ChartAreas[Target_Index].AxisX.MajorTickMark.Interval;

           Ypixel = Inner_Height * Ydel / (Ymax - Ymin);
           Xpixel = Inner_Width * Xdel / (Xmax - Xmin);

               if (Xpixel > Ypixel)
               {
                   Target.ChartAreas[Target_Index].AxisX.Maximum = Inner_Width * Xdel / Ypixel + Xmin;
               }
               else
               {
                   Target.ChartAreas[Target_Index].AxisY.Maximum = Inner_Height*Ydel/Xpixel + Ymin;
               }
           } while (Math.Abs(Math.Log(Xpixel/Ypixel, 10))>0.01);

       }
   }

Please, help me to solve this. Thanks!
Posted
Comments
Sunasara Imdadhusen 11-Jun-14 2:13am    
Using above code what you will get?
LucasRLS 24-Jun-14 14:53pm    
My coordinate charts are turning circles to elipses! lol
I can't upload images...
My programam are used to develop calculations of design, printing the results on scripts (for Ansys and ICEM). I need a fair interface to the user verify the features before print.

1 solution

I just need to implement it as a PrePaint. As my program is resizeble, I had to do a similar function to implement at Resize Event. Othe requisite is the required redraw of charts. For that, I must have a stoper, I suggest to use a if condition (Foo.Zoom_). I removed my project info of this publication, but I will be glad to answer personal questions.
C#
public void Square_PrePaint()
        {
            double deltaY = Chart.ChartAreas[0].AxisY.Maximum - Chart.ChartAreas[0].AxisY.Minimum;
            double deltaX = Chart.ChartAreas[0].AxisX.Maximum - Chart.ChartAreas[0].AxisX.Minimum;
 
            double Lenght_Y = Chart.ClientSize.Height;
            double Lenght_X = Chart.ClientSize.Width;
 
            double ratioX = deltaX / Lenght_X;
            double ratioY = deltaY / Lenght_Y;
            double diference = Math.Abs(ratioX - ratioY) / Math.Max(ratioX, ratioY);
 
            if (diference > 0.02)
            {
                deltaX = ((int)(deltaY / Lenght_Y * Lenght_X)) + 1;
 

                Chart.ChartAreas[0].AxisX.Minimum = Chart.ChartAreas[0].AxisX.Maximum - deltaX;
 
                Foo.Zoom_.X_max = Chart.ChartAreas[0].AxisX.Maximum;
                Foo.Zoom_.Y_max = Chart.ChartAreas[0].AxisY.Maximum;
                Foo.Zoom_.X_min = Chart.ChartAreas[0].AxisX.Minimum;
                Foo.Zoom_.Y_min = Chart.ChartAreas[0].AxisY.Minimum;
 
                Foo.Zoom_.Activeted = true;
                chart.Update();
            }
        }
 
Share this answer
 

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



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