Category Item labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
phamdinhnguyen
Posts: 22
Joined: Thu Jan 29, 2004 8:28 pm

Category Item labels

Post by phamdinhnguyen » Mon Mar 01, 2004 5:57 pm

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
Last edited by phamdinhnguyen on Thu Mar 18, 2004 11:22 pm, edited 1 time in total.

Clemens
Posts: 4
Joined: Fri Feb 13, 2004 12:05 pm

Post by Clemens » Fri Mar 05, 2004 10:10 am

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:

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);
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?
regards,
Clemens

"Fascinating is a word i use for the unexpected" [Mr. Spock]

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 » Fri Mar 05, 2004 3:48 pm

David Gilbert
JFreeChart Project Leader

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

Clemens
Posts: 4
Joined: Fri Feb 13, 2004 12:05 pm

Post by Clemens » Mon Mar 08, 2004 7:24 am

The answer in the mentioned thread is not very satisfying, because
  • I cannot group the categories any more
  • I'm not dealing with dates
But the scrolling solution is OK for me. Is there any possibility to limit the length of the category labels - some kind of renderer would be nice :?
regards,
Clemens

"Fascinating is a word i use for the unexpected" [Mr. Spock]

phamdinhnguyen
Posts: 22
Joined: Thu Jan 29, 2004 8:28 pm

Category labels issues

Post by phamdinhnguyen » Thu Mar 18, 2004 6:00 pm

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

Guest

Post by Guest » Tue Aug 02, 2005 10:09 pm

Please, could give me un example of code with the last API please?
Thanks.

Guest

Post by Guest » Tue Aug 02, 2005 10:44 pm

please what is the MINIMUM_CATEGORY_SIZE constant? Is it in the jfreedoc?
and what is m_analysis? the dataset?

thanks.

Guest

Post by Guest » Tue Aug 02, 2005 11:25 pm

I also would like to know what type is the argument in the JScrollPanel constructor in this case. thanks.

Locked