我正在制作一个使用 gnuplot 的 Java 应用程序。我已经成功地在JPanel
(使用JPlot
)中显示了一个图表。但是我需要以某种方式访问 JavaPlot 提供给 gnuplot 的命令,或者我需要显示它们并直接编辑它们。这就是我坚持的问题;JavaPlot 对我来说太复杂了,找不到方法来做到这一点。
我尝试在(下面GNUPlotParameters
的代码)的构造函数中使用,PlotHandler
但它似乎不起作用。我能够得到一些结果:
class PlotHandler { //my own class that works with the JPlot
private String gnuplotpath;
private JavaPlot p;
PlotHandler(String path){
this.gnuplotpath=path;
/*doesn't work
GNUPlotParameters para = new GNUPlotParameters();
para.set("size 900 900");
p = new JavaPlot(para,gnuplotpath,new DefaultTerminal());
*/
//this does:
p = new JavaPlot(gnuplotpath);
p.setTitle("spectrum");
p.getAxis("x").setLabel("wave length");
p.getAxis("y").setLabel("absorbance");
}
JPlot getGraph(){
JPlot plot;
((AbstractPlot) p.getPlots().get(0)).getPlotStyle().setStyle(Style.LINES);
plot = new JPlot(p);
plot.getJavaPlot().plot();
return plot;
}
}
GUI:
...
JPlot plot = plotHandler.getGraph();
System.out.println(plot.getJavaPlot().getCommands()); //this seems to work, but I'm not sure that it would work if I somehow passed some commands thru the GNUPlotParameters.
总而言之,我需要一些方法,比如
JPlot.getJavaPlot.setCommands(String commands)
和
String commands = JPlot.getJavaPlot.getCommands()
(getCommands()
实际上存在,我只是不知道它是否按我的意愿工作)