先看看結果!
再看看主要核心語法吧!
private void BtnPlot_Click(object sender, EventArgs e)
{
try
{
if (this.txtRcode.Text == "")
{
Rcode = @"library('scatterplot3d')
z <- seq(-8, 8, 0.01)
x <- cos(z)
y <- sin(z)
scatterplot3d(x, y, z, main='3d',pch=20)
";
}
else
{
Rcode = this.txtRcode.Text;
}
engine = REngine.GetInstance();
engine.Initialize();
string rnd = System.Guid.NewGuid().ToString().Replace("-", "");
string filename = "i" + rnd + "__Rimage.png";
engine.Evaluate(string.Format("png(file='{0}',bg ='transparent',width={1},height={2})", filename, this.ptbGraphic.Width, this.ptbGraphic.Height));
engine.Evaluate(Rcode);
engine.Evaluate("dev.off()");
string path = System.IO.Path.GetFullPath(filename);
Bitmap image = new(path);
ptbGraphic.Image = image;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
留言列表