如何在java中制作成绩条形图

时间:2015-03-12 17:13:33

标签: java bar-chart stddraw

这是我的作业问题,但我似乎无法直截了当。该程序提示用户输入学生人数,然后提示用户输入每个学生的成绩百分比(0-100)。我唯一不能做对的是我无法在正确的位置绘制列。列将相隔0.5个空格。注意学生的数量是水平轴,等级是垂直轴。我在代码中包含的评论是我需要帮助的。谢谢

import java.util.*;
import javax.swing.JOptionPane;


public class GradesChart{
  public static void main (String [] args) {

  drawAxes(); //Call method to draw the axes intersecting at (0.1,0.1)

  String input = JOptionPane.showInputDialog(null,"Please enter the number of students.");
  int input2 = Integer.parseInt(input);

  double columnnWidth = 0.5; // *** HOW TO CALCULATE THE COLUMN WIDTH???****

  for (int grade = 0; grade < input2; grade++){
      JOptionPane.showInputDialog(null, "Please enter the grade of student. ");
    drawColumn(columnnWidth, input2 , grade);
    /**IN THIS FOR LOOP I WANT TO PROMPT USER TO ENTER THE GRADE OF EACH STUDENT (0-100)
    AND DRAW A COLUMN THAT REPRESENTS THE GRADE **/
  }
  }

  public static void drawAxes() {
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.line(0.0,1.0,0.0,0.0);
    StdDraw.line(0.0,0.0,1.0,0.0);
  }

  public static void drawColumn(double width, int studentIndex, int grade) {
    StdDraw.setPenColor(StdDraw.BLUE);
    StdDraw.filledRectangle(studentIndex, grade, width, 1.0);
  }

}

1 个答案:

答案 0 :(得分:0)

使用JFreeCharts库。有关详细信息,请参阅此示例:http://www.tutorialspoint.com/jfreechart/jfreechart_bar_chart.htm