Hi forum,
I have a rather large dataset in my chart. This ofcourse gives a lot
of labels on the category axis. Is it possible to reduce the numer
of labels on the axis (ex skipping every n), but still keeping the same numbers in the dataset.
When creating charts in Excel this is done automagicly.
I have purschased the PDF document but I still can't figure out how to do it.
/Lars
Reducing category labels
same problem with large x-values on CategoryDataset

can someone help on this situation?
In my case there is another need: i have on x-axis some continous values (date values) but depending on my query this can get a lot of values (ex. all days on one o two years range). So i need a category chart representing this y-values as bar chart.
But also if chart is represented ok, all labels of x-axis are collapsed and seems too near each-others that char result not readable....but this could be solved if we can set some tick unit on x-axis as for timeseries chart!!!!
-
- Posts: 11
- Joined: Wed Apr 20, 2005 1:55 pm
- Location: India
hi lars_ohlen,
if i am getting your question correctly then you have to set tick level through the setTickLevel method. Try this.
And now sdotolo,
you have to over-write a method "drawSubCategoryLabels" of class "CategoryAxis" in axis package.
=============================
RefineryUtilities.drawRotatedString(label, g2, xx, (yy + 10), TextAnchor.CENTER, TextAnchor.CENTER, this.bottomAngle);
==============================
use this line to draw string where bottomAngle defined rotation.
if i am getting your question correctly then you have to set tick level through the setTickLevel method. Try this.
And now sdotolo,
you have to over-write a method "drawSubCategoryLabels" of class "CategoryAxis" in axis package.
=============================
RefineryUtilities.drawRotatedString(label, g2, xx, (yy + 10), TextAnchor.CENTER, TextAnchor.CENTER, this.bottomAngle);
==============================
use this line to draw string where bottomAngle defined rotation.
Rahul K. Gupta
-
- Posts: 6
- Joined: Sun Oct 31, 2004 10:09 pm
Re: Reducing category labels
Skipping Categorylabels for barcharts and stackedbarcharts was supported in an old version but the feature was removed by the author after 9.13 I think. When having dates as categories this is a really useful feature but it is currently not supported as far as I know. Fortunately there is a workaround. This works for me (9.20)lars_ohlen wrote:Hi forum,
I have a rather large dataset in my chart. This ofcourse gives a lot
of labels on the category axis. Is it possible to reduce the numer
of labels on the axis (ex skipping every n), but still keeping the same numbers in the dataset.
When creating charts in Excel this is done automagicly.
I have purschased the PDF document but I still can't figure out how to do it.
/Lars
guest wrote:JFreeChart 0.9.13
// customise the domain axis...
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setVerticalCategoryLabels(true);
domainAxis.setSkipCategoryLabelsToFit(true);
JFreeChart 0.9.20
// create categories label...
String[] categories = new String[100];
for (int i=0; i<categories.length; i++) {
categories = "Data"+String.valueOf(i);
}
// prepare for skip label categories...
String[] extendedCategories = new String[ categories.length ];
for( int i=0; i< categories.length; i++ )
{
if( i%5 == 0 )
extendedCategories = categories;
else
extendedCategories = " ";
}
... produce chart ....
// get a reference to the plot for further customisation...
CategoryPlot plot = chart.getCategoryPlot();
// set skip label categories...
final ExtendedCategoryAxis extendedCategoryAxis = new ExtendedCategoryAxis(null);
for (int i=0; i<categories.length; i++) {
extendedCategoryAxis.addSubLabel(categories, extendedCategories);
}
Font theFont = extendedCategoryAxis.getTickLabelFont();
extendedCategoryAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 0));
extendedCategoryAxis.setSubLabelFont(theFont);
plot.setDomainAxis(extendedCategoryAxis);