change font size of the diffrent values of Domain axis

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
hepzibahr
Posts: 13
Joined: Mon Sep 04, 2006 2:33 pm

change font size of the diffrent values of Domain axis

Post by hepzibahr » Wed Apr 16, 2008 10:27 am

Basically i want to wrap the values displayed on the x axis (Not the xaxis title)and change the font size as well because the length of the values exceed 30 characters.

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 » Wed Apr 16, 2008 3:43 pm

You didn't say what type of axis you are using.
David Gilbert
JFreeChart Project Leader

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

hepzibahr
Posts: 13
Joined: Mon Sep 04, 2006 2:33 pm

Post by hepzibahr » Wed Apr 16, 2008 4:32 pm

Sorry ,Iam using Domain axis (Y axis ) and Range axis (X axis). i want to change the font of the Domain axis values and if possible as a two line text
containing the product code and product description

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 » Wed Apr 16, 2008 4:38 pm

"Domain axis" is a general term we use to describe the x-axis, and "range axis" is likewise referring to the y-axis. But I need to know the Java class you are using - is it a CategoryAxis, NumberAxis, DateAxis, or something else?
David Gilbert
JFreeChart Project Leader

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

hepzibahr
Posts: 13
Joined: Mon Sep 04, 2006 2:33 pm

Post by hepzibahr » Wed Apr 16, 2008 4:47 pm

As of now i have not used any specific one for Domain axis but for Range axis I am using DateAxis ..Should i use categoryaxis for Domain axis

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 » Thu Apr 17, 2008 9:23 am

If you don't specify the axis type, one will be assigned for you by JFreeChart. How do you create your chart? Maybe it would be a good idea if you posted a small self-contained demo showing what you have so far.
David Gilbert
JFreeChart Project Leader

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

hepzibahr
Posts: 13
Joined: Mon Sep 04, 2006 2:33 pm

Post by hepzibahr » Thu Apr 17, 2008 12:57 pm

Hallo Dave ,

This is what i have ...I do get my chart .But now i want to enhance the Domain axis values to display an additional field therfore have to change the font size and display in two lines instead of all being in one line

private JFreeChart createChart(CategoryDataset dataset) {
JFreeChart chart = ChartFactory.createBarChart(null, // title
"Parts", // domain axis label
"Value", // range axis label
dataset, // dataset
PlotOrientation.HORIZONTAL, // orientation
true, // include legend
false, // tooltips
false // URLs
);
chart.setBackgroundPaint(new Color(
0xFF, 0xFF, 0xCC));
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.BLUE);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.lightGray);
plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(1.0f);
//plot.getDomainAxis().setMaximumCategoryLabelLines(4);
// plot.getDomainAxis().setLabelFont(new Font("Helvetica", Font.PLAIN, 6)); //This changes only the Domain axis label
DateAxis rDate = new DateAxis("Date");
rDate.setRange(fromDate, ToDate);
rDate.setDateFormatOverride(new SimpleDateFormat("MM/yy"));
plot.setRangeAxis(rDate);
CategoryItemRenderer renderer = new LineAndShapeRenderer(
false, true);
CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator(
"{2}", DateFormat.getDateInstance());
renderer.setItemLabelGenerator(generator);
renderer.setItemLabelFont(new Font(
"Helvetica", Font.PLAIN, 6));
renderer.setItemLabelsVisible(true);
ItemLabelPosition position = new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_LEFT,
TextAnchor.BOTTOM_LEFT, -0.7);
renderer.setPositiveItemLabelPosition(position);

Marker currDay = new ValueMarker(
day.getMiddleMillisecond());
currDay.setPaint(Color.red);
currDay.setLabelFont(new Font(
"Helvetica", Font.PLAIN, 6));
currDay.setLabel(today);
plot.addRangeMarker(currDay);
plot.setRenderer(renderer);
return chart;
}

Thanks a lot for your help

hepzibahr
Posts: 13
Joined: Mon Sep 04, 2006 2:33 pm

Post by hepzibahr » Fri Apr 18, 2008 7:18 am

CategoryAxis axis = plot.getDomainAxis();
axis.setTickLabelFont(new Font("Helvetica", Font.PLAIN, 6));
axis.setMaximumCategoryLabelWidthRatio(1.0f);
axis.setMaximumCategoryLabelLines(2);
plot.setDomainAxis(axis );


With this i could change the font of the domain axis values but not word wrap

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 Apr 18, 2008 4:14 pm

hepzibahr wrote:This is what i have ...I do get my chart .But now i want to enhance the Domain axis values to display an additional field therfore have to change the font size and display in two lines instead of all being in one line
I think for this you'll probably be best to create a custom CategoryAxis. That will probably involve overriding refreshTicks(), returning a list of customised ticks (instead of the existing CategoryTick class), and then overriding the drawCategoryLabels() method to handle the specialised drawing. Finally, you'll probably have to override the reserveSpace() method to ensure that the chart layout works correctly, detecting the size of your labels to ensure that there is the right amount of space for them to be drawn.
David Gilbert
JFreeChart Project Leader

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

Locked