Category Item labels
-
- Posts: 22
- Joined: Thu Jan 29, 2004 8:28 pm
Category Item labels
My chart has large number of categories, ie > 600.
All category item labels are crowded over one another resulting in unreadable blacken texts.
Is there a (simple) way to:
a) display category labels at a fixed interval, say one label for each 30 categories, and
b) obviously, need to preserve the chart with all 600 categories.
Thanks
phamdinhnguyen
All category item labels are crowded over one another resulting in unreadable blacken texts.
Is there a (simple) way to:
a) display category labels at a fixed interval, say one label for each 30 categories, and
b) obviously, need to preserve the chart with all 600 categories.
Thanks
phamdinhnguyen
Last edited by phamdinhnguyen on Thu Mar 18, 2004 11:22 pm, edited 1 time in total.
I also have a chart which a huge number of categories. For me it's important to have all category labels readable, so I put the chart into a scrollpane. After a while of investigation I found out one way it works fine for me. Have a look at my code, maybe it helps:
I use JFreeChart 0.9.16. My only problem, I still couldn't solve is, to limit th e length of the labels along the category axis. If a label is too long, I want to truncate it and put ... at the end of the label. Does someone have any ideas how to do that?
Code: Select all
// calculate preferred size for chart panel
int size = this.m_analysis.getColKeys().size() * MINIMUM_CATEGROY_SIZE;
int width = ChartPanelConstants.DEFAULT_WIDTH;
int height = ChartPanelConstants.DEFAULT_HEIGHT;
int minWidth = ChartPanelConstants.DEFAULT_MINIMUM_DRAW_WIDTH;
int minHeight = ChartPanelConstants.DEFAULT_MINIMUM_DRAW_HEIGHT;
int maxWidth = ChartPanelConstants.DEFAULT_MAXIMUM_DRAW_WIDTH;
int maxHeight = ChartPanelConstants.DEFAULT_MAXIMUM_DRAW_HEIGHT;
// find category axis
if (m_chart.getCategoryPlot().getOrientation().equals(PlotOrientation.HORIZONTAL)) {
height = size;
minHeight = size;
maxHeight = size;
width = 20;
} else {
width = size;
minWidth = size;
maxWidth = size;
height = 20;
}
// create chart panel with calculated size
cp =
new ChartPanel(
m_chart,
width,
height,
minWidth,
minHeight,
maxWidth,
maxHeight,
true,
false,
false,
false,
false,
true);
m_scrollPane.getViewport().setView(cp);
// margins are interpreted as factor of the category-axis size
// so inherit them from the number of categories
m_chart.getCategoryPlot().getDomainAxis().setUpperMargin((double) 2 / size);
m_chart.getCategoryPlot().getDomainAxis().setLowerMargin((double) 2 / size);
this.add(m_scrollPane, BorderLayout.CENTER);
regards,
Clemens
"Fascinating is a word i use for the unexpected" [Mr. Spock]
Clemens
"Fascinating is a word i use for the unexpected" [Mr. Spock]
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


The answer in the mentioned thread is not very satisfying, because

- I cannot group the categories any more
- I'm not dealing with dates

regards,
Clemens
"Fascinating is a word i use for the unexpected" [Mr. Spock]
Clemens
"Fascinating is a word i use for the unexpected" [Mr. Spock]
-
- Posts: 22
- Joined: Thu Jan 29, 2004 8:28 pm
Category labels issues
Clemens,
Have you tried to change the orientation of your category labels?
I had the same issue, and this is my simple customization for my chart that has too many category labels as well as being long.
private void customizeChart(Parms localParm)
{
localParm.oChart.setBackgroundPaint(Color.getHSBColor(178, 201, 6));
localParm.oPlot = localParm.oChart.getCategoryPlot();
localParm.oAxis = localParm.oPlot.getDomainAxis();
localParm.oAxis.setCategoryMargin(0.25); // twenty-five percent
localParm.oAxis.setLowerMargin(0.04); // four percent
localParm.oAxis.setUpperMargin(0.04); // four percent
localParm.oAxis.setMaxCategoryLabelWidthRatio(10);
if(localParm.oChartOrientation == PlotOrientation.VERTICAL)
localParm.oAxis.[b]setCategoryLabelPositions(CategoryLabelPositions.DOWN_90)[/b];
} // end customizeChart()
Good luck!
phamdinhnguyen
Have you tried to change the orientation of your category labels?
I had the same issue, and this is my simple customization for my chart that has too many category labels as well as being long.
private void customizeChart(Parms localParm)
{
localParm.oChart.setBackgroundPaint(Color.getHSBColor(178, 201, 6));
localParm.oPlot = localParm.oChart.getCategoryPlot();
localParm.oAxis = localParm.oPlot.getDomainAxis();
localParm.oAxis.setCategoryMargin(0.25); // twenty-five percent
localParm.oAxis.setLowerMargin(0.04); // four percent
localParm.oAxis.setUpperMargin(0.04); // four percent
localParm.oAxis.setMaxCategoryLabelWidthRatio(10);
if(localParm.oChartOrientation == PlotOrientation.VERTICAL)
localParm.oAxis.[b]setCategoryLabelPositions(CategoryLabelPositions.DOWN_90)[/b];
} // end customizeChart()
Good luck!
phamdinhnguyen