Hi
Is it possible to display the Legend inside the plot area or chartArea (not ouside or bottom).
Awaiting for ur reply.....
Thanx
Raj
Legend Position
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
There is some code to do this, but it is still experimental - see:
org.jfree.experimental.chart.annotations.XYTitleAnnotation.java
org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
org.jfree.experimental.chart.annotations.XYTitleAnnotation.java
org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


XYTitleAnnotation coordinate arguments
Can you please elaborate on the (x,y) coordinate arguments in the XYTitleAnnotation constructor?
It seems they are in the range [0, 1]. On a standard date domain axis, the x coordinate behaves like a percentage (x=.05 puts the legend 5% away from the left of the chart).
But the interaction with LogAxis is confusing. My legend at y=.2 appears in the middle of my chart, rather than 20% away from the bottom as I expect.
The difference between log axis values is 70 at the bottom, and 1400 at the top. Changes in the XYTitleAnnotation value of y for low values of y affect the position more than the same changes for high values of y.
I guess the y value is used as a percentage of the absolute range values, but I expected it to be a percentage of pixels on the chart.
Would it be reasonable/practical to change the coordinate system to pixels instead of range values?
Thanks!
It seems they are in the range [0, 1]. On a standard date domain axis, the x coordinate behaves like a percentage (x=.05 puts the legend 5% away from the left of the chart).
But the interaction with LogAxis is confusing. My legend at y=.2 appears in the middle of my chart, rather than 20% away from the bottom as I expect.
The difference between log axis values is 70 at the bottom, and 1400 at the top. Changes in the XYTitleAnnotation value of y for low values of y affect the position more than the same changes for high values of y.
I guess the y value is used as a percentage of the absolute range values, but I expected it to be a percentage of pixels on the chart.
Would it be reasonable/practical to change the coordinate system to pixels instead of range values?
Thanks!
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
I'm glad that you are trying out this experimental code. The coordinates can be expressed as RELATIVE values (0.0 to 1.0) which should correspond to a linear scale over the plot's data area, or DATA values (which will use the axes to translate the position to Java2D space). There's also an INDEX option, which is intended to allow the annotation to be attached to a data value at a certain index position in the dataset - I don't think that is implemented yet.
I don't recall testing this with the LogAxis, so I'll give that a try.
I don't recall testing this with the LogAxis, so I'll give that a try.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: XYTitleAnnotation coordinate arguments
Hi there.mickish wrote:Can you please elaborate on the (x,y) coordinate arguments in the XYTitleAnnotation constructor?
It seems they are in the range [0, 1]. On a standard date domain axis, the x coordinate behaves like a percentage (x=.05 puts the legend 5% away from the left of the chart).
But the interaction with LogAxis is confusing. My legend at y=.2 appears in the middle of my chart, rather than 20% away from the bottom as I expect.
The difference between log axis values is 70 at the bottom, and 1400 at the top. Changes in the XYTitleAnnotation value of y for low values of y affect the position more than the same changes for high values of y.
I guess the y value is used as a percentage of the absolute range values, but I expected it to be a percentage of pixels on the chart.
Would it be reasonable/practical to change the coordinate system to pixels instead of range values?
Thanks!
I worked a bit with that and I didnt find a easy way to place the annotation in a relative way. What I found is the x,y coords must be x,y values where you want your annotation on your serie.
If there's a way to place the annotation at a specific x,y coords, let me know.
Best regards.,
Phil
-
- Posts: 1
- Joined: Fri Jan 03, 2014 7:25 pm
- antibot: No, of course not.
Re: Legend Position
Here's a hack that seems to work. If P is the desired fractional distance from the edge of the axis and min is the min of the range and max is the max of the range, then the value to use will be:
min * (10 ^ P log10(max) - 1 ) / (max - min)
So, for example, if P = 0.02, min = 0.01, max = 500 the value to use will be 0.000023 (a very small number!)
I figured this out my looking at
org.jfree.chart.annotations.XYTitleAnnotation
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
ValueAxis domainAxis, ValueAxis rangeAxis,
int rendererIndex, PlotRenderingInfo info)
and
org.jfree.chart.axis.LogAxis.java
public double valueToJava2D(double value, Rectangle2D area,RectangleEdge edge)
It's rather horrible to figure out.
min * (10 ^ P log10(max) - 1 ) / (max - min)
So, for example, if P = 0.02, min = 0.01, max = 500 the value to use will be 0.000023 (a very small number!)
I figured this out my looking at
org.jfree.chart.annotations.XYTitleAnnotation
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
ValueAxis domainAxis, ValueAxis rangeAxis,
int rendererIndex, PlotRenderingInfo info)
and
org.jfree.chart.axis.LogAxis.java
public double valueToJava2D(double value, Rectangle2D area,RectangleEdge edge)
It's rather horrible to figure out.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Legend Position
This approach should also work:
In the draw-method, replace the calculations of j2DX and j2DY with
In the draw-method, replace the calculations of j2DX and j2DY with
Code: Select all
float j2DX = dataArea.getMinX() + this.x*dataArea.getWidth();
float j2DY = dataArea.getMinY() + this.y*dataArea.getHeight();