0

I have a question about a JFreeChart issue. I want to display a chart with a line from the values out of my database. This is the code I have now:

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();
    }
}

After executing the code, it gives me a chart with no lines in it. Only a x and y axis. What should I do to get a line in the chart.

3
  • So is it working or not.Are you getting any error ?What is your question? Commented Dec 8, 2013 at 12:58
  • and the question is...... ? Commented Dec 8, 2013 at 12:58
  • After executing the code it gives me a chart with no lines in it. Only a x and y axis. What should i do to get a line in the chart. Commented Dec 8, 2013 at 14:35

1 Answer 1

1

Try JDBCXYDataset, mentioned here. Because "the first column will be the x-axis," change your query to "select date, status from luggage". JDBCXYDataset can detect a time series based on metadata, so ChartFactory.createTimeSeriesChart() may be a suitable choice.

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried, but i want the graph to select all the number 0s from my status column in the DB. I am getting a weird graph right now.
You might also need to check for NULL, for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.