ticklabel in barcharts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
guest

ticklabel in barcharts

Post by guest » Fri Jan 16, 2004 7:47 pm

Hii,

In the chart, for category axis i m using the dates. When the data is small, the date tick labels are displayed correctly. But, when the data is large..the date tick labels are overlapping. Is there any way to skip some tick labels to display the dates properly in the xaxis.

My present code looks like this.

Code: Select all

		CategoryAxis categoryAxis = new CategoryAxis(getChartItems().getXAxisLabel()); 
		categoryAxis.setAxisLineVisible(true);
		categoryAxis.setTickMarksVisible(true);
		CategoryLabelPosition position = new CategoryLabelPosition( 
			RectangleAnchor.CENTER,TextBlockAnchor.CENTER, TextAnchor.CENTER, -Math.PI / 2.0 
		); 
		categoryAxis.setBottomCategoryLabelPosition(position);
		categoryAxis.setLabelFont(labelFont);
		categoryAxis.setLabelInsets(new Insets(15,5,5,5));
		categoryAxis.setTickLabelFont(tickLabelFont);
		
		plot.setDomainAxis(categoryAxis);
Can someone give ideas??

Regards,
guest

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 » Mon Jan 19, 2004 10:27 am

If possible, try to use an XYPlot with a DateAxis - then you'll have more control over the labelling options.
David Gilbert
JFreeChart Project Leader

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

AdamWarlock

RE: Post subject: ticklabel in barcharts

Post by AdamWarlock » Wed Jan 21, 2004 7:46 pm

Don't know if this is of any help but I am using CEWolf in a JSP page to do something similiar and I am getting the correct spacing between the various data point labels on the x aixs by doing the following...


public void processChart( Object chart, Map params )
{
CategoryPlot plot = (CategoryPlot)((JFreeChart)chart).getPlot();

// Set the colors of the four data series. 0=Inventory Target, 1=UCL, 2=LCL, 3=Inventory
CategoryItemRenderer renderer = plot.getRenderer();
renderer.setSeriesPaint(0, Color.black);
renderer.setSeriesPaint(1, Color.red);
renderer.setSeriesPaint(2, Color.red);
renderer.setSeriesPaint(3, Color.blue);

// Set the background gradient
// Paint p = new GradientPaint(0, 0, Color.white, 0, 200, Color.lightGray);
// plot.setBackgroundPaint(p);
plot.setDomainGridlinesVisible(true);

// Adjust the x-axis
HorizontalCategoryAxis x_axis = (HorizontalCategoryAxis) plot.getDomainAxis();
// x_axis.setVerticalCategoryLabels(true);
x_axis.setSkipCategoryLabelsToFit(true);
x_axis.setTickMarksVisible(true);
}

The relvant line is x_axis.setSkipCategoryLabelsToFit(true);

Hope this helps..

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

The relvant line is x_axis.setSkipCategoryLabelsToFit(true);

Post by phamdinhnguyen » Thu Mar 18, 2004 10:16 pm

AdamWarlock,

This method setSkipCategoryLabelsToFit(true) is no longer available in the latest release.
I've done some scouting in this forum, and found out many developers are facing this same issue. We prefer the solution your recommend: setSkipCategoryLabelsToFit(true).
What version of JFreeChart do you use?
I assume that you didn't upgrade to the latest JFreeChart, as your codes will break?

phamdinhnguyen

Locked