change font size of the diffrent values of Domain axis
change font size of the diffrent values of Domain axis
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.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
You didn't say what type of axis you are using.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
"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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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
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
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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.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
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

