[C#]如何在图表中制作方形网格线? [英] [C#] How do I make square grid lines in a Chart?

查看:145
本文介绍了[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!

推荐答案

我只需将其作为PrePaint实现。由于我的程序可以重新调整,我必须在Resize Event中执行类似的功能。其他必要条件是需要重绘图表。为此,我必须有一个stoper,我建议使用if条件( Foo.Zoom _ )。我删除了此出版物的项目信息,但我很乐意回答个人问题。

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.
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#]如何在图表中制作方形网格线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆