本文介绍了[C#]如何在图表中制作方形网格线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用方形网格线来实现图表。 X中的delta的像素值需要与Y中的delta相同。它是如何做的?这个apper非常简单,但我没有在c#中找到例子。我尝试过,但是值不会在图表运行时修改后收敛...



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!

推荐答案

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();
            }
        }


这篇关于[C#]如何在图表中制作方形网格线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:41