0

我有这个程序来显示读取arrayList 的点图。但是当我运行它时,它只显示一个点,我不知道为什么。我想问题出在获取 y 坐标上,但我不知道如何解决,有人知道为什么吗?

    private static final double MARGIN = 50;
private GOval point;
private double xDistance;
private double yDistance;
private double X_START;
private double Y_START;

public void run(){

    ArrayList <Double> numberList= createListOfNumbers();
    drawLineGraph(numberList);
}


private ArrayList <Double> createListOfNumbers(){
    ArrayList <Double> numberList = new ArrayList <Double>() ;

        numberList.add(2.3);
        numberList.add(4.4);
        numberList.add(6.6);
        numberList.add(5.7);
        numberList.add(8.5);
        numberList.add(10.4);
        numberList.add(12.3);
        numberList.add(9.6);
        numberList.add(13.1);

    return numberList;
}
private void drawLineGraph(ArrayList numberList){

    xDistance = (getWidth()-(MARGIN*2))/(numberList.size()-1);; //*distance between points
    yDistance = (getHeight()-(MARGIN*2)/((max(numberList)-min(numberList))*100));


    double x=0;
    double y=0;

    for (int i=0; i<numberList.size();i++){

        x = (i*xDistance+MARGIN);
        y = (((max(numberList)-(Double) numberList.get(i))*100)*yDistance+MARGIN)+100;
        /*create a new point*/
        point = new GOval (10,10);
        point.setFilled(true);
        add (point, x,y);
    }
}

private double max(ArrayList numberList){
    double max= (Double) numberList.get(0);

    for (int i=0;i < numberList.size();i++){
        if ((Double) numberList.get(i)>max){
            max= (Double) numberList.get(i);

        }
    }
    return max;
}
private double min(ArrayList numberList){
    double min=(Double) numberList.get(0);

    for (int i=0;i < numberList.size();i++){
        if ((Double) numberList.get(i)<min){
            min= (Double) numberList.get(i);
        }
    }
    return min;
}

}

4

0 回答 0