Results 1 to 6 of 6
  1. #1
    saneel4u is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default Jfreechart api- bar chart

    Hi,
    I want to create a bar chart using timeseries dataset. But in the output, instead of getting all bars of same color(default red), I am getting some bars of white color. Also some bars look less dark than others. What could be the reason for it?

    The following is my code:

    final TimeSeries series = new TimeSeries("Test Data");

    String query = "SELECT * FROM report";
    try
    {
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery(query);
    while (rs.next())
    {

    java.sql.Timestamp td= rs.getTimestamp("Date");
    Double a= rs.getDouble("Average");
    System.out.println(td + " timestamp " + a +" average");
    int year = td.getYear();
    int month = td.getMonth();
    int day = td.getDay();
    int hours = td.getHours();
    int minutes = td.getMinutes();
    int seconds = td.getSeconds();

    Date dtest= new Date(year,month,day,hours,minutes,seconds);
    FixedMillisecond ftest= new FixedMillisecond(dtest);
    series.add(ftest,a);
    }
    }
    catch (SQLException ex)
    {
    System.err.println(ex.getMessage());
    }
    final TimeSeriesCollection dataset = new TimeSeriesCollection(series);
    IntervalXYDataset data1 = dataset;

    JFreeChart chart = ChartFactory.createXYBarChart(
    title,
    "Date",
    true,
    "Price",
    data1,
    PlotOrientation.VERTICAL,
    true,
    true,
    false
    );
    XYPlot plot = (XYPlot)chart.getPlot();
    XYItemRenderer r = plot.getRenderer();
    XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator(StandardXYToolTipGenera tor.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), NumberFormat.getNumberInstance());
    r.setBaseToolTipGenerator(toolTipGenerator);
    if(r instanceof XYLineAndShapeRenderer)
    {
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)r;
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    }

    XYBarRenderer renderer2 = new XYBarRenderer();
    renderer2.setShadowVisible(false);
    plot.setRenderer(0, renderer2);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 400));
    setContentPane(chartPanel);

    This is the screenshot:


    On zooming,

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default

    For me, the links to those images are broken; I can't see what you mean.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    saneel4u is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default link

    Hi,
    If you right click and open image in a new tab, you can see it. I have attached the image here.


    or


    Uploaded with ImageShack.us

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default

    Could it be a pixel resolution issue? Try to plot just a few vertical bars and see what happens.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    saneel4u is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    yeah, I plotted a few bars, and still even among them, some of the bars come white. Even if I manually set the colors of the bars, the bars with white color have no effect on them. But they do actually represent data points.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by saneel4u View Post
    yeah, I plotted a few bars, and still even among them, some of the bars come white. Even if I manually set the colors of the bars, the bars with white color have no effect on them. But they do actually represent data points.
    Sorry, I don't know much about jfreechart; they seem to have a forum but it's filled with spam; maybe they have a bug section. Best of luck with it, I can't help you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JFreeChart 1.0.11
    By Java Tip in forum Java Software
    Replies: 3
    Last Post: 04-18-2014, 08:27 PM
  2. Jfreechart
    By aaruviswa in forum Web Frameworks
    Replies: 2
    Last Post: 03-17-2011, 06:51 AM
  3. JfreeChart
    By puk284 in forum Advanced Java
    Replies: 1
    Last Post: 05-12-2009, 04:52 PM
  4. Demo bar chart and pie chart
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:22 PM
  5. JFreeChart 1.0.5
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-10-2007, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •