有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在JFreeChart linechart中显示数据库值

我有一个关于JFreeChart问题的问题。我想显示一个图表,其中有一行来自数据库中的值。这是我现在拥有的代码:

public void drawachart(){
    try{
        String sql= "select status,date from luggage";
        JDBCCategoryDataset dataset = new JDBCCategoryDataset(
            "jdbc:mysql://localhost/corendon", "com.mysql.jdbc.Driver", "root", "root");
        dataset.executeQuery(sql);
        JFreeChart chart = ChartFactory.createLineChart("chart","date", "status",
            dataset,PlotOrientation.VERTICAL,false,true,true);
        BarRenderer bar= null;
        bar = new BarRenderer();
        CategoryPlot plot =null;
        ChartFrame frame = new ChartFrame("shart", chart);
        frame.setVisible(true);
        frame.setSize(500, 500);
    }
    catch(Exception e){
        e.printStackTrace();
    }
}

执行代码后,它会给我一个没有行的图表。只有x轴和y轴。我应该怎么做才能在图表中画出一条线


共 (1) 个答案

  1. # 1 楼答案

    试试^{},提到here。因为“第一列将是x轴”,所以将查询更改为"select date, status from luggage"JDBCXYDataset可以基于元数据检测时间序列,因此ChartFactory.createTimeSeriesChart()可能是一个合适的选择