Ahhhhh

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Guest

Ahhhhh

Post by Guest » Fri Feb 11, 2005 9:43 pm

ok I give up

I can't figure out how to use JDBCXYDataset to create a TimeSeries BarChart; it either comes up as line chart or NO chart

anyone know how to do this?!

oacis
Posts: 101
Joined: Fri Jan 07, 2005 5:57 am
Location: Australia, Sydney

Post by oacis » Mon Feb 14, 2005 12:43 am

Set the renderer on the plot to be a bar renderer

ie

Code: Select all

xyPlot.setRenderer(int index, XYItemRenderer renderer);
// or
xyPlot.setRenderer(XYItemRenderer renderer);

Guest

Post by Guest » Mon Feb 14, 2005 4:16 pm

This works

Code: Select all

JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, "Dollars", dataset, true, true, false);
            
chart.setBackgroundPaint(Color.WHITE);
         
XYPlot xyplot = chart.getXYPlot();
            
XYAreaRenderer renderer = new XYAreaRenderer();
            
xyplot.setRenderer(0, renderer);

This doesn't =(

Code: Select all

JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, "Dollars", dataset, true, true, false);
            
chart.setBackgroundPaint(Color.WHITE);
         
XYPlot xyplot = chart.getXYPlot();
            
XYBarRenderer renderer = new XYBarRenderer();
            
xyplot.setRenderer(0, renderer);
I want my BAR, but i just get a big X on the image

Guest

Post by Guest » Mon Feb 14, 2005 5:38 pm

very very frustrated =(

why does area work but not bar?!?!?!

khipras
Posts: 15
Joined: Mon Feb 07, 2005 6:41 pm
Location: Mexico D.F.
Contact:

Post by khipras » Tue Feb 15, 2005 12:13 am

You should use

new JDBCCategoryDataset(connection); instead JDBCXYDataset to chart Bar...

And then
make chart with
JFreeChart barChart = ChartFactory.createBarChart3D("3D Example", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false);

Guest

Post by Guest » Tue Feb 15, 2005 7:59 pm

but I need a Timeseries chart =)

khipras
Posts: 15
Joined: Mon Feb 07, 2005 6:41 pm
Location: Mexico D.F.
Contact:

Post by khipras » Tue Feb 15, 2005 9:50 pm

..... why?
any special feature?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Feb 15, 2005 11:43 pm

Anonymous wrote:very very frustrated =(

why does area work but not bar?!?!?!
The XYBarRenderer class needs an IntervalXYDataset (the x-interval defines the width of the bars). Unfortunately, the JDBCXYDataset interface doesn't implement the IntervalXYDataset interface (only XYDataset, this could probably be fixed). One way to get around this is to create an XYBarDataset to wrap around your JDBCXYDataset instance and use that as your dataset. The bar width in the constructor will need to be specified in milliseconds (along the axis) for time series data.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Guest

Post by Guest » Wed Feb 16, 2005 7:00 pm

it works now =)

thanks !

Guest

Post by Guest » Tue Feb 22, 2005 7:20 pm

do you know why all my bars are a thin line? How do I change the width bar to larger?

Code: Select all


JDBCXYDataset dataset = null;

//fill dataset

XYBarDataset xybar = new XYBarDataset(dataset, 0);
            
JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, "Dollars", xybar, false, true, false);

chart.setBackgroundPaint(Color.WHITE);
            
XYPlot xyplot = chart.getXYPlot();
         
XYBarRenderer renderer = new XYBarRenderer(0);
            
xyplot.setRenderer(0, renderer);


response.setContentType("image/png");
            
ChartUtilities.writeChartAsPNG(out, chart, 448, 252);


Guest

Post by Guest » Fri Feb 25, 2005 10:54 pm

any clue?

caa
Posts: 21
Joined: Mon Feb 14, 2005 11:28 pm

Post by caa » Thu Mar 24, 2005 4:35 pm

Because your interval width is set to 0.
Read Davids reply, the width is milliseconds along the axis. I'm using 600000.0 which is 10 minutes, as I have datapoints every 10 minutes.
I first tried 300000.0 because I have 2 datapoints, but it splits the bars into the alloted interval.

It works well.
Charles Anderson

Guest

Post by Guest » Wed Apr 13, 2005 3:44 pm

caa wrote:I'm using 600000.0 which is 10 minutes, as I have datapoints every 10 minutes....blabla...It works well
I use constant MILLISECONDS_IN_HOUR = 60L * 1000L * 60L for charts with datapoints evety hour.
But what should I do with month charts? Every month have different size in milliseconds and that's why i've got february that is much wider than other ones...
Any suggestion?...

Thx a lot!

j0medina
Posts: 17
Joined: Sat Aug 30, 2003 12:30 am
Location: Milwaukee
Contact:

Post by j0medina » Wed Apr 13, 2005 4:36 pm

Personally when I do reporting by months I use category plots/renderers/datasets with the month string (04/2005, etc.) being the category. Then in my programs logic and sql I pass the data to the dataset in the correct order. This way the bar widths and spacing are uniform.

Locked