How can I make a graph as shown in the image?

enter image description here Currently, when I run this code, it shows me a graph, as shown above, I want to draw the graph that I showed. Currently, when drawing a graph symmetrical about (0,0), I think that forcing him to draw from (0, -3) or (0, <-2), this work should be done. Is there any other way to do this?

Current Code:

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);



    }
}
+3
source share
1 answer

XYAreaRenderer. . XYAreaRenderer.drawItem(). transZero, (0.0). 0.0 , , , , .

- , XYAreaRenderer drawItem(). , .

,

XYAreaRenderer yourNewRenderer = ...; /* initialize here */
chart.getXYPlot().setRender(yourNewRenderer);
0

All Articles