我想知道如何在XY图上的jfreechart中绘制线条,点(或小圆圈),矩形和梯形。其中大多数从某些坐标到范围零基线。我必须代表这样的寻根方法:
http://www2.lv.psu.edu/ojj/courses/cmpsc-201/201-images/bisect.jpg
或辛普森这样的规则:
http://upload.wikimedia.org/wikipedia/commons/0/08/Simpson_rule.png
我已经有了找到解决方案和绘图的功能,我只需要在某些坐标中绘制形状。我是jfreechart和绘图的新手,我一直在寻找方法。
我的情节代码:
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.plot.XYPlot;
public class Grafica1 {
JFreeChart grafica;
XYSeriesCollection datos=new XYSeriesCollection();
String titulo;
String etiquetax;
String etiquetay;
int cont=1;
public Grafica1(String t, String x, String y){
titulo=t;
etiquetax=x;
etiquetay=y;
grafica=ChartFactory.createXYLineChart(titulo, x, y, datos, PlotOrientation.VERTICAL, true, true, true);
XYPlot plot= (XYPlot) grafica.getPlot();
//plot.setDomainZeroBaselineVisible(true);
plot.setRangeZeroBaselineVisible(true);
}
public Grafica1(){
this("Sin título", "x", "y");
}
public void agregarGrafica(String id, double[] x, double[] y){
XYSeries s=new XYSeries("["+(cont++)+"] "+id);
int n=x.length;
for(int i=0;i<n;i++){
s.add(x[i], y[i]);
}
datos.addSeries(s);
}
public void crearGrafica(String id, double[] x, double[] y){
cont=1;
datos.removeAllSeries();
agregarGrafica(id, x, y);
}
public JPanel obtieneGrafica(){
return new ChartPanel(grafica);
}
}