Time Series BAR Charts

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

Time Series BAR Charts

Post by Amit » Wed Feb 19, 2003 11:16 pm

Currently the createTimeSeriesChart draws only an XY plot.
Is there a way I can get the "Time usage" but in a bar chart.
The advantage of the Time usage is that the dates are compressed with increase in the data.

Thanks

Justin Johnson

Re: Time Series BAR Charts

Post by Justin Johnson » Thu Feb 20, 2003 7:00 pm

You can create an VerticalXYBarRenderer and add it to the plot.

TimeSeriesCollection dataset = new TimeSeriesCollection();
.
.
.

XYItemRenderer renderer = new VerticalXYBarRenderer(0.20);
XYPlot plot = new XYPlot(dataset, null, null, renderer);

Amit

Re: Time Series BAR Charts

Post by Amit » Fri Feb 21, 2003 5:51 pm

Question on your recommendation .... how do I add my variables to the TimeSeriesCollection ?
I have the dates and some numbers for each date.

Thanks

Justin Johnson

Re: Time Series BAR Charts

Post by Justin Johnson » Fri Feb 21, 2003 6:55 pm

Amit,

Create a BasicTimeSeries based on some unit of time (Second, Minute, Hour, Month, ...) and add your data points to it. Then add the BasicTimeSeries to your TimeSeriesCollection. I did something like this where I looped through the data and converted each date into a Second, then added it to the BasicTimeSeries. Then created the renderer like I described above and added my TimeSeriesCollection to it.

import com.jrefinery.data.Second;

.
.
.
TimeSeriesCollection availableDataset = new TimeSeriesCollection();
BasicTimeSeries available = new BasicTimeSeries("Available Licenses", Second.class);

available.add(mySecond, some_value);

availableDataset.addSeries(available);

Amit

Re: Time Series BAR Charts

Post by Amit » Fri Feb 21, 2003 7:23 pm

My case is os dates (YYYY-MM-DD) .... there is not date type for that.

In your case, you are converting the dates into seconds.
But there are 2 potential problems with that.
1. You lose the feel of date ... as you are recoding them to seconds.
2. If the seconds range from 0 to 60 (not sure of that though), then you have a limited amount of data to work with.

Thanks

Justin Johnson

Re: Time Series BAR Charts

Post by Justin Johnson » Fri Feb 21, 2003 10:55 pm

The time period just has to be unique so that all your data points can be displayed. It doesn't have to do with the format of the date that appears. I chose Second because I knew I would never have more than one data item per second, but I could potentially have multiple data items per minute, so Minute would not work for me. If you only have one data entry per year, use Year. Does that make sense?

Amit

Re: Time Series BAR Charts

Post by Amit » Mon Feb 24, 2003 6:28 pm

Thanks Justin, I was able to create the bar chart. But got into a new problem now, Is there a way I can paint the Bars differently. Ex all the Bars on weekends, should be of a different color.

Thanks

Justin Johnson

Re: Time Series BAR Charts

Post by Justin Johnson » Mon Feb 24, 2003 7:06 pm

Try

plot.setSeriesPaint(0, new Color(51, 153, 255));

or some other color and series number.

Amit

Re: Time Series BAR Charts

Post by Amit » Wed Mar 05, 2003 8:15 pm

There is another problem that I am encountering now.
How do I plot time in case of StackedBar Charts ?
Or in case of Bar charts that have 6 bars (Categories) per day ?

Thanks

Locked