English 中文(简体)
• 如何做图像所示的图表?
原标题:How can i make a graph as shown in image?

enter image description here 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);



    }
}
问题回答

目前在<代码>XYAreaRenderer中对此没有支持。 然而,执行这一点太困难。 查阅<代码>XYAreaRenderer.drawItem()方法。 在这一方法中,有一套当地变数的<代码>transZero,使用实际零值(0.0)计算。 如果你只是以某种其他价值取代0.0,这很可能是你所需要的。

实现这一点的最容易的方法是创建来自XYAreaRenderer和压倒性drawItem(<>>>>/code>的自成因。 这种方法复制了原法典,并如上所述加以修改。

然后,你才需要用书面方式使用这一新的理论。

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




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...