Hello,
I was wondering if it would be possible to get the XLabel and YLabel from a JFreeChart object. I searched the Javadoc and saw that I can get the Title of the chart, or even the Legend items, but I can't figure how to get the axis labels. I know that these labels only exist in some types of charts, such as bar charts, and I assume this is the reason why there is no getXLabel() method in the JFreeChart class. Nevertheless, it must be stored somewhere.
I am using JFreeChart v1.0.13 and JDK v1.6.0_21.
Thank you for your time.
Get X and Y Labels from a JFreeChart
Re: Get X and Y Labels from a JFreeChart
Depends on which labels you are looking for. First, get a reference to the axis by calling plot.getDomainAxis(...) or plot.getRangeAxis(...)
The base class org.jfree.chart.axis.Axis defines this method
If you are looking for the actual tick labels, call this method
Each element of the returned List is an instance of org.jfree.chart.axis.Tick
The base class org.jfree.chart.axis.Axis defines this method
Code: Select all
public String getLabel()
Code: Select all
public abstract java.util.List refreshTicks(java.awt.Graphics2D g2,
AxisState state,
java.awt.geom.Rectangle2D dataArea,
org.jfree.ui.RectangleEdge edge)
Re: Get X and Y Labels from a JFreeChart
Thank you ! Problem solved !
For future reference, this is the exact code I used :

For future reference, this is the exact code I used :
Code: Select all
JFreeChart chart = ChartFactory.createBarChart3D(...);
...
String xLabel = chart.getCategoryPlot().getDomainAxis().getLabel();
String yLabel = chart.getCategoryPlot().getRangeAxis().getLabel();