JFreeChart 和 Hibernate 中的问题

Issue in JFreeChart and Hibernate

有人可以帮我解决这个问题吗?我正在尝试使用休眠数据库创建图表,但我在 for 循环中遇到错误“实际和形式参数列表的长度不同”。我尝试在线查找此错误,但没有找到任何解决方案。我决定从这里寻求帮助。任何帮助将不胜感激

这是我的实体的代码 class:

class Student1
{
    private int rno,marks1,marks2,marks3;
    private String name;

public Student1() {  }

public Student1(int rno,String name,int marks1,int marks2,int marks3)
{
    this.rno = rno;
    this.name = name;
    this.marks1 = marks1;
    this.marks2 = marks2;
    this.marks3 = marks3;

 //getter and setters
}

方法图代码如下:

public static void chartsStudent()
{

    DefaultCategoryDataset d1 = new DefaultCategoryDataset();

    Configuration cfg = new Configuration();
    cfg.configure("hibernate.cfg.xml");

    SessionFactory sfact = cfg.buildSessionFactory();
    Session session = null;

    try
    {
        session = sfact.openSession();
        System.out.println("connected");
        session.beginTransaction();

        List<Student1> student1list = new ArrayList<>();
        student1list = session.createQuery("from Student1").list();
        
        for(Student1 b : student1list)
        {
            d1.setValue(b.getName(),b.getMarks1(),b.getMarks2(),b.getMarks3());
        }
        
    }
    catch(Exception e)
    {
        System.out.println(e.getMessage());
    }
    finally
    {
        if (session !=null)
        {
            session.close();
            System.out.println("disconnected");
        }
    }
JFreeChart chart = ChartFactory.createBarChart("Student Preformance",
"Subjects","Marks",d1,PlotOrientation.VERTICAL,true,true,false);
int width = 400;
int height = 400;
}

错误

如前所述,添加或设置值的 , the DefaultCategoryDataset 增变器都采用 三个 个参数,而不是 四个 。每个 value 是感兴趣的 Number,每个 rowKey 是一个系列,每个 columnKey 是系列中的一个元素。例如,

public void setValue(double value, Comparable rowKey, Comparable columnKey)

根据你的Studentclass,每个值是grade/mark,每个系列(rowKey)是一个学生的名字,每个元素(columnKey) 是一个 assignment/test.

d1.setValue(b.getMarks1(), b.getName(), "Test1");
d1.setValue(b.getMarks2(), b.getName(), "Test2");
…

或者,JDBCCategoryDataset builds a CategoryDataset from a SQL query in one step; the source is an example; more may be found here