Currently when i run this code it shows me a graph as shown above, i want to draw a graph that i ve shown. Currently its drawing a graph symmetric about the (0,0), I think making it drawn from (0,-3) or (0, < -2) should do the work. Is there any other way for doing this?
现行法典:
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);
}
}