目前,当我运行此代码时,它向我显示了一个如上所示的图表,我想绘制一个我已经显示的图表。目前它绘制一个关于 (0,0) 对称的图形,我认为从 (0,-3) 或 (0, < -2) 绘制它应该可以完成工作。有没有其他方法可以做到这一点?
当前代码:
public class Profile {
double last=0;
ChartFrame frame1;
JToolBar jt=new JToolBar();
public void generateProfile(int[] pointValue,double[] distance){
ArrayList pv=new ArrayList();
ArrayList dist=new ArrayList();
pv.add(pointValue);
dist.add(distance);
int min=pointValue[0];
for(int i=0;i<pv.size();i++){
//System.out.print(pointValue[i]);
if(pointValue[i]<min){
min=pointValue[i];
}
}
for(int i=0;i<dist.size();i++){
System.out.print(distance[i]);
}
XYSeries series = new XYSeries("Average Weight");
for(int i=0;i<pointValue.length;i++){
//if(pointValue[i]!=0){
series.add(last,pointValue[i]);
last=distance[i];
//}
}
XYDataset xyDataset = new XYSeriesCollection(series);
JFreeChart chart= ChartFactory.createXYAreaChart("Profile View Of Contour", "Distance", "Contour Value", xyDataset, PlotOrientation.VERTICAL, true, true, false);
ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();
rangeAxis.setLowerBound(-3);
frame1=new ChartFrame("XYLine Chart",chart);
JButton saveimg=new JButton(new AbstractAction("Save as Image"){
public void actionPerformed(ActionEvent e) {
//some other lines of code...
}
});
jt.add(saveimg);
frame1.add(jt, BorderLayout.NORTH);
frame1.setVisible(true);
frame1.setSize(300,300);
}
public static void main(String ar[]){
Profile pro=new Profile();
int[] pv={2,3,0,5,-2,10};
double[] dist={1,4,8,12,14,20};
pro.generateProfile(pv, dist);
}
}