Two quick questions about XYBarCharts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tedbyers
Posts: 50
Joined: Fri Oct 12, 2007 7:05 pm

Two quick questions about XYBarCharts

Post by tedbyers » Thu May 15, 2008 6:41 pm

1) The charts appear fine now, with the labels. The labels are, in fact doubles to be interpreted as percent. Is there an easy way to tack the '%' character onto the end of the label produced by the default generator? In other charts, where the figures are currency, is there a similarly easy way to tack a '$' onto the front of the default label?

2) The labels appear correctly centred above, or below, the bar. However, the domain axis markers appear only at the edges of the bars. The dataset is a time series collection BTW, if that matters. So, the marker for January 2000 appears on the left edge of the bar representing the gain for that month, and the marker for February 2000 appears at the right edge of that bar. It would be better if the domain axis markers appeared in the middle of the bar it corresponds to. Is there a simpe way to do this?

Thanks

Ted

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Re: Two quick questions about XYBarCharts

Post by skunk » Thu May 15, 2008 6:56 pm

tedbyers wrote:1) The charts appear fine now, with the labels. The labels are, in fact doubles to be interpreted as percent. Is there an easy way to tack the '%' character onto the end of the label produced by the default generator? In other charts, where the figures are currency, is there a similarly easy way to tack a '$' onto the front of the default label?
Use this constructor

Code: Select all

public StandardXYItemLabelGenerator(java.lang.String formatString, java.text.NumberFormat xFormat, java.text.NumberFormat yFormat)

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

Re: Two quick questions about XYBarCharts

Post by david.gilbert » Thu May 15, 2008 8:25 pm

tedbyers wrote:2) The labels appear correctly centred above, or below, the bar. However, the domain axis markers appear only at the edges of the bars. The dataset is a time series collection BTW, if that matters. So, the marker for January 2000 appears on the left edge of the bar representing the gain for that month, and the marker for February 2000 appears at the right edge of that bar. It would be better if the domain axis markers appeared in the middle of the bar it corresponds to. Is there a simpe way to do this?
Look for the setTickMarkPosition() method in the DateAxis class.
David Gilbert
JFreeChart Project Leader

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

tedbyers
Posts: 50
Joined: Fri Oct 12, 2007 7:05 pm

Re: Two quick questions about XYBarCharts

Post by tedbyers » Thu May 15, 2008 8:34 pm

david.gilbert wrote:
tedbyers wrote:2) The labels appear correctly centred above, or below, the bar. However, the domain axis markers appear only at the edges of the bars. The dataset is a time series collection BTW, if that matters. So, the marker for January 2000 appears on the left edge of the bar representing the gain for that month, and the marker for February 2000 appears at the right edge of that bar. It would be better if the domain axis markers appeared in the middle of the bar it corresponds to. Is there a simpe way to do this?
Look for the setTickMarkPosition() method in the DateAxis class.
Found it, but now the domain axis has two too many markers. For a data set containing values for January 2000 through December 2000, the domain axis shows markers also for December 1999 and Jabuary 2001.

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 » Thu May 15, 2008 8:37 pm

What are the lower and upper margins for the axis? If you reduce these, the extra labels will probably disappear.
David Gilbert
JFreeChart Project Leader

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

tedbyers
Posts: 50
Joined: Fri Oct 12, 2007 7:05 pm

Post by tedbyers » Thu May 15, 2008 9:19 pm

david.gilbert wrote:What are the lower and upper margins for the axis? If you reduce these, the extra labels will probably disappear.
I used the defaults. The time series gets only month objects. that is why I was surprised that the month before the series starts and the month after it ends appear as markers.

A puzzle is why the data axis has a function to take a double, but not one of your date related objects.

OOPS, I just found your functions to set the maximum date and minimum date. What is very odd, though, is that they require a java.util.Date argument, and won't accept your date related classes such as org.jfree.data.time.Month. You know, of course, that java.util.Date is depricated, and that makes working with them a Royal PITA. Perhaps this is a part of your library that ought to be refactored a) to use Sun's Calendar classes and b) to accept your own date related classes. You seem to have put a lot of effort into creating them, for your time series charts, so it is a bit incongruous not to be able to use them directly in, e.g. your DateAxis class.

Thanks

Ted

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 » Thu May 15, 2008 9:29 pm

tedbyers wrote:I used the defaults. The time series gets only month objects. that is why I was surprised that the month before the series starts and the month after it ends appear as markers.
If your dataset was numerical, and in the range 0.5 to 9.5, you probably wouldn't be surprised to see 0.0 and 10.0 on your x-axis. It isn't much different for dates.
tedbyers wrote:You know, of course, that java.util.Date is depricated, and that makes working with them a Royal PITA.
java.util.Date has NOT been deprecated. Many of its methods have been deprecated, but its basic function of recording a "point in time" to the nearest millisecond is still valid and very much in use.
tedbyers wrote:Perhaps this is a part of your library that ought to be refactored a) to use Sun's Calendar classes and b) to accept your own date related classes. You seem to have put a lot of effort into creating them, for your time series charts, so it is a bit incongruous not to be able to use them directly in, e.g. your DateAxis class.
Not really. The time period classes used in the TimeSeries and TimeSeriesCollection classes don't represent "points in time", but rather time periods...so it doesn't really make sense to specify the lower bound or the upper bound of the axis using a time period...that's why the axis still uses java.util.Date for the bounds.
David Gilbert
JFreeChart Project Leader

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

tedbyers
Posts: 50
Joined: Fri Oct 12, 2007 7:05 pm

Post by tedbyers » Thu May 15, 2008 9:33 pm

One last question, I hope. I have created a decent 2D bar chart with timer series data. I used:

TimeSeriesCollection
TimeSeries
ChartFactory.createXYBarChart

Code: Select all

        org.jfree.chart.axis.DateAxis axis = (org.jfree.chart.axis.DateAxis) plot.getDomainAxis();
        axis.setTickMarkPosition(org.jfree.chart.axis.DateTickMarkPosition.MIDDLE);
        org.jfree.data.time.Month mtmp = Dates.get(0);
        java.util.Calendar gc = java.util.Calendar.getInstance();
        gc.set(mtmp.getYearValue(),mtmp.getMonth()-1,1);
        axis.setMinimumDate(gc.getTime());
        int ubv = Dates.size() - 1;
        mtmp = Dates.get(ubv);
        gc = java.util.Calendar.getInstance();
        gc.set(mtmp.getYearValue(),mtmp.getMonth()-1,31);
        axis.setMaximumDate(gc.getTime());
        
        org.jfree.chart.renderer.xy.XYBarRenderer renderer = (org.jfree.chart.renderer.xy.XYBarRenderer) plot.getRenderer();
 org.jfree.chart.renderer.category.BarRenderer3D) plot.getRenderer();
        renderer.setDrawBarOutline(false);
        renderer.setBaseItemLabelGenerator(new org.jfree.chart.labels.StandardXYItemLabelGenerator());
 org.jfree.chart.labels.StandardCategoryItemLabelGenerator());
        renderer.setMargin(0.1);
        renderer.setSeriesPaint(0, dg);
        renderer.setSeriesItemLabelsVisible(0, labelsCheckBox.isSelected());
Now the boss wants it recast as a 3D bar chart. Is there a relatively straight forward way to change the existing chart into 3D chart, or do I have to rewrite it all de novo using one of your category datasets?

He also wanted to know if I could use a different colour for each bar (and as there are a number of related charts, he wants the same colour for a given month in one chart to match that used for the same month in a different chart. Is that possible without too much pain?

Thanks

Ted

Locked