Пример #1
0
        void Instance_graphicCreated(object sender, EventArgs e)
        {
            GraphicCreatedEventArgs args = (GraphicCreatedEventArgs)e;

            imgContador++;

            Process          process   = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.WindowStyle      = ProcessWindowStyle.Hidden;
            startInfo.WorkingDirectory = Application.StartupPath;
            startInfo.FileName         = "cmd.exe";
            startInfo.Arguments        = "/C " + "echo F | xcopy " + args.location.Replace('/', '\\') + " Imagenes\\imagen" + imgContador + ".png";
            process.StartInfo          = startInfo;
            process.Start();
            process.WaitForExit();
            pbGrafica.ImageLocation = "Imagenes\\imagen" + imgContador + ".png";


            /// Eliminando imagenes anteriores
            Process          p2  = new Process();
            ProcessStartInfo si2 = new ProcessStartInfo();

            si2.WindowStyle      = ProcessWindowStyle.Hidden;
            si2.WorkingDirectory = Application.StartupPath + "\\Imagenes";
            si2.FileName         = "cmd.exe";
            si2.Arguments        = "/C " + "for %i in (*) do if not %i == imagen" + imgContador + ".png del %i ";
            p2.StartInfo         = si2;
            p2.Start();
            process.WaitForExit();
        }
Пример #2
0
        public void graficaXY(int[] x, double[] y, int height = 480, int width = 480, string xlabel = "", string ylabel = "", string imageName = "xyplot", string y_scale = "")
        {
            StringBuilder imports = new StringBuilder();

            imports.Append("library(ggplot2)");

            StringBuilder xString = new StringBuilder();

            xString.Append("x <- c(");
            for (int i = 0; i < x.Length; i++)
            {
                if (i != 0)
                {
                    xString.Append(",");
                }
                xString.Append(x[i].ToString());
            }
            xString.Append(")");

            StringBuilder yString = new StringBuilder();

            yString.Append("y <- c(");
            for (int i = 0; i < y.Length; i++)
            {
                if (i != 0)
                {
                    yString.Append(",");
                }
                yString.Append(y[i].ToString());
            }
            yString.Append(")");

            String Rxlabel    = "PNGxlabel <- \"" + xlabel + "\"";
            String Rylabel    = "PNGylabel <- \"" + ylabel + "\"";
            String RHeight    = "PNGheight <- " + height.ToString();
            String RWidth     = "PNGwidth <- " + width.ToString();
            String RImageName = "imageName <- \"" + imageName + "\"";

            System.IO.File.WriteAllLines(pathR + "/variables.R", new string[] { imports.ToString(), xString.ToString(), yString.ToString(), Rxlabel, Rylabel, RHeight, RWidth, RImageName, y_scale }, Encoding.Default);

            runCommand("del .RData");
            runCommand("R < variables.R --save");
            runCommand("R < xyPlot.R --no-save");
            if (graphicCreated != null)
            {
                GraphicCreatedEventArgs args = new GraphicCreatedEventArgs();
                args.location = pathR + "/" + imageName + ".png";
                args.name     = imageName;
                graphicCreated(this, args);
            }
        }