Two quick questions about XYBarCharts
Two quick questions about XYBarCharts
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
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
Re: Two quick questions about XYBarCharts
Use this constructortedbyers 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?
Code: Select all
public StandardXYItemLabelGenerator(java.lang.String formatString, java.text.NumberFormat xFormat, java.text.NumberFormat yFormat)
-
- 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
Look for the setTickMarkPosition() method in the DateAxis class.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?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: Two quick questions about XYBarCharts
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 wrote:Look for the setTickMarkPosition() method in the DateAxis class.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?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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.david.gilbert wrote:What are the lower and upper margins for the axis? If you reduce these, the extra labels will probably disappear.
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
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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: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.
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:You know, of course, that java.util.Date is depricated, and that makes working with them a Royal PITA.
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.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.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


One last question, I hope. I have created a decent 2D bar chart with timer series data. I used:
TimeSeriesCollection
TimeSeries
ChartFactory.createXYBarChart
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
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());
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