Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: problem in plotting graph for same x-axis values

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default problem in plotting graph for same x-axis values

    hello
    I have plotted graph from database using jfreechart.it works fine for different x-axis values but how to plot for same x-axis values
    values in database(test) are
    tim(x-axis) mem(y-axis)
    2012-02-13 15:12:43.508 408889999
    2012-02-13 15:12:43.508 800000567
    2012-02-13 16:12:43.508 96345678

    here is my code


    import java.text.ParseException;
    import org.jfree.ui.*;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.plot.Plot;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.data.jdbc.JDBCCategoryDataset;
    import org.jfree.data.xy.XYDataset;
    public class Chart
    {
    public static void main(String[] args) throws Exception
    {
    //Calendar cal = Calendar.getInstance();

    String query = "SELECT * from chart";
    //cal.set(year, month, date, hourOfDay, minute);
    JDBCCategoryDataset dataset = new JDBCCategoryDataset("jdbc:mysql://localhost:3306/test", "com.mysql.jdbc.Driver","root", "root");

    dataset.executeQuery(query);




    JFreeChart chart = ChartFactory.createLineChart("Test", "Id", "Score",dataset, PlotOrientation.VERTICAL, true,true,true);
    ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    ApplicationFrame f = new ApplicationFrame("Chart");
    f.setContentPane(chartPanel);
    f.pack();
    f.setVisible(true);

    //JFreeChart chart1 = ChartFactory.createLineChart("Test", "Id", "Score", dataset, PlotOrientation.VERTICAL, true,true,true);
    //ChartPanel chartPane2 = new ChartPanel(chart1);
    }
    }



    what changes we have to make in above code inorder to get plot for same x-axis values.

    please help me.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: problem in plotting graph for same x-axis values

    What does the API doc say for the classes you are using?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: problem in plotting graph for same x-axis values

    it says datetime(x-axis) versus memory used(y-axis) which is plotted in graph...which is taken from database.

Similar Threads

  1. how to plot a line graph by reading the values from database?
    By priti in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2012, 01:39 AM
  2. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  3. Plotting updated graph continuously
    By sudhan in forum Java Theory & Questions
    Replies: 0
    Last Post: October 17th, 2011, 09:28 PM
  4. Java Bar graph takes user input to create graph?
    By kenjiro310 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2011, 07:37 AM
  5. Plotting w/JFreeCharts
    By Javajava in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 12th, 2010, 10:02 AM