VerticalXYBars and TimeSeriesChart

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

VerticalXYBars and TimeSeriesChart

Post by Jim McLaughlin » Tue Mar 26, 2002 7:51 pm

Hi Dave and developer team,

I'm creating a TimeSeries/BarChart (using a VerticalXYBarRenderer) and I have a couple questions.

First, it seems like Bars always want to start at 0 on the rangeAxis. drawItem in VerticalXYBarRenderer takes a parameter translatedRangeZero which XYPlot always scales from zero even if the RangeAxis has setAutoScaleIncludesZero set to false. Do I need to hack some code to get translatedRangeZero to map from the minimum RangeAxis value or is there a method I'm missing?

Second, since there is no break between my TimePeriods, there is no spacing between the bars. Any suggestions on how to get some spacing between them (CategoryPlot, perhaps)?

Thanks again for all your work on JfreeChart!

Jim McLaughlin

David Gilbert

Re: VerticalXYBars and TimeSeriesChart

Post by David Gilbert » Tue Mar 26, 2002 11:14 pm

Hi Jim,

On your first question, the base of the bars is always at zero. If zero is off the plot, then the clipping should take care of it...is it causing a problem?

Second: the bar widths are determined by the start and end of the underlying time periods (if you are using the TimeSeriesCollection class). The important methods are getStartXValue(...) and getEndXValue(...) in the IntervalXYDataset interface...you could hack the TimeSeriesCollection class to alter the values that it is returning for these methods. Or, since the values are ultimately calculated by the time periods themselves, create a new TimePeriod subclass that returns a different start and end value...for example, if you have daily data you might return the millisecond value for 9am as the start of the day, and the millisecond value for 6pm as the end of the day.

Hope that helps,

DG.

Jim McLaughlin

Re: VerticalXYBars and TimeSeriesChart

Post by Jim McLaughlin » Wed Mar 27, 2002 12:45 am

Hi Dave,

Thanks for your reply. Clipping takes care of it, I just wanted to have the vert axis scale to be more precise. I hacked the code so that translatedRangeZero takes the minAxis value for the range axis. If anyone else does this, make sure subtract a percent off of your real min y val or your smallest bar won't show :).

I'll give a try to deriving a new TimePeriod subclass. Thanks for your help.

Jim

David Gilbert

Re: VerticalXYBars and TimeSeriesChart

Post by David Gilbert » Thu Mar 28, 2002 4:08 pm

Jim,

I had another idea for handling this. It works quite well, so I've made the change for version 0.8.1. Basically I've taken the VerticalXYBarRenderer and added a margin property. This is a percentage that gets trimmed off the width of the bars, so if you specify 0.20 (20%) then 10% gets taken off the left side, and 10% off the right side.

Here's the code that I added right before the bar is created in the VerticalXYBarRenderer:

if (margin>0.0) {
double cut = translatedWidth * margin;
translatedWidth = translatedWidth - cut;
translatedStartX = translatedStartX + cut/2;
}

I've tested it with the Day subclass of TimePeriod, but it should work with all the others too.

Regards,

DG.

Locked