嗨,大家好
我想问,如果有人成功地与JRI和r
Java合作?我想把一些图表,R中的图表放到我的Java应用程序中,但没有成功.任何人都可以提供工作实例.这是我发现的,但它不起作用.谢谢
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
/**
* @author Nero
*In this file, i will try to plot a simple example, only to test how it?s possible to plot through java
*Attention: Nothing will work if you have not included the JRI.jar as library ( through properties)*/
public class TryPlot {
public static void main(String[] args) {
// TODO Auto-generated method stub
//start the Rengine (JRI)
Rengine re = new Rengine(null, false, null);
//in R: >a
double da[] = {1.2, 2.3, 4.5};
long xp3 = re.rniPutDoubleArray(da);
re.rniAssign("a", xp3, 0);
//look up for a:
REXP x;
x = re.eval("a");
System.out.println(x);
//THE PROBLEM: The window opens, but nothing happens???
re.eval(" plot(a)");
}
}
最佳答案 我认为普通的R图形设备只有在R GUI中使用时才有效,而不是从java或命令行启动.
所以我使用“JavaGD”包作为图形设备,这很好用.
Plot以普通的JFrame打印,甚至可以通过子类化来扩展.