Reducing category labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
lars_ohlen
Posts: 2
Joined: Fri May 13, 2005 4:06 pm

Reducing category labels

Post by lars_ohlen » Mon May 16, 2005 11:05 am

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

sdotolo
Posts: 4
Joined: Mon Jul 19, 2004 4:31 pm

same problem with large x-values on CategoryDataset

Post by sdotolo » Wed Jun 08, 2005 12:12 pm

:cry: hi, i'm having the same problem but cannot find a valid solution also if i have bought the last PDF document, hoping this could help me...but nothing !!!

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!!!!

Rahul Gupta
Posts: 11
Joined: Wed Apr 20, 2005 1:55 pm
Location: India

Post by Rahul Gupta » Wed Jun 08, 2005 1:32 pm

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.
Rahul K. Gupta

Jonteponte
Posts: 6
Joined: Sun Oct 31, 2004 10:09 pm

Re: Reducing category labels

Post by Jonteponte » Wed Jun 08, 2005 2:07 pm

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
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)
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);

Locked