DrawLine - peace098beat/windows_applicaciton GitHub Wiki


        public void picturebox1_plot()
        {


            int total = data.GetLength(0);
            int skip = 1;
            int picture_width = pictureBox1.Width;
            int picture_height = pictureBox1.Height;

            Graphics g = pictureBox1.CreateGraphics();


            // データ変換
            float[] float_data1 = new float[data.GetLength(0)];
            for (int i = 0; i < data.GetLength(0); i++) float_data1[i] = float.Parse(data[i][1]);
            while ((double)total / (double)skip > picture_width) skip++;
            // ひとつ大きいぐらい
            skip = skip - 1;


            int plotdata_length = (int)((double)total / (double)skip);

            // 座標変換
            int viewport(float x, float x0, float x1, int X0, int X1)
            {
                return (int)((float)(x - x0) / (float)(x1 - x0) * (float)(X1 - X0));
            }

            
            int[] Xs = new int[plotdata_length];
            int[] Ys = new int[plotdata_length];

            float ymin = float_data1.Min(); // 計算めっちゃ遅い
            float ymax = float_data1.Max(); // 計算めっちゃ遅い
            float yratio = (float)(pictureBox1.Height - 0.0) / (ymax - ymin);
            
            for (int gi = 0; gi < plotdata_length; gi++)
            {
                Xs[gi] = gi;
                Ys[gi] = viewport(float_data1[(gi) * skip], ymin, ymax, 0, picture_height);
            }

            Pen p = new Pen(Color.Black, 1); // Penオブジェクトの作成(幅3黒色)
            for (int gi = 1; gi < plotdata_length; gi++)
            {
                g.DrawLine(p, Xs[gi - 1], Ys[gi - 1], Xs[gi], Ys[gi]); // 100ms
            }

            //リソースを解放する
            g.Dispose();

        }