I am trying to add an XYPointerAnnotation to a combined line chart. The XYPointerAnnotation constructor requires an X and Y value which I think are absolute to the complete chart area.
How can I calculate the X and Y value from a given domain and range value?
Regards,
Erik.
How to get x,y for XYPointerAnnotation in simple line chart?
-
- Posts: 8
- Joined: Tue Aug 30, 2005 10:42 am
-
- Posts: 8
- Joined: Tue Aug 30, 2005 10:42 am
How to get x,y for XYPointerAnnotation in simple line chart?
Of course, x and y are not absolute, but very much exactly the domain and range values. Problem solved!
How to get x,y for XYPointerAnnotation in simple line chart?
Next problem: you can not specify to which vertical axis the annotation should be resolved. I have several but the range value (the Y) is always resolved against the first.
The following method may be a temporal solution in solving this:
A final solution should be additional methods on XYPlot.
Regards,
Erik.
The following method may be a temporal solution in solving this:
Code: Select all
XYPlot chartPlot = ...;
ValueAxis defaultRangeAxis = chartPlot.getRangeAxis();
ValueAxis usedRangeAxis = chartPlot.getRangeAxis(........);
String msg = ...;
double domainValue = ...;
double rangeValue = ...;
double annotationValue = convertToAxis(rangeValue, usedRangeAxis, defaultRangeAxis);
XYPointerAnnotation pointerAnnotation = new XYPointerAnnotation(
msg, domainValue, annotationValue, angle);
chartPlot.addAnnotation(pointerAnnotation );
Code: Select all
/**
* Converts a number so that it can be used on another axis.
* @param source a number against source axis
* @param srcAxis the source axis
* @param dstAxis the destination axis
* @return the number on the same number against the destination axis
*/
private static double convertToAxis(double source, ValueAxis srcAxis, ValueAxis dstAxis) {
double result;
if (srcAxis == dstAxis) {
result = source;
} else {
Range srcRange = srcAxis.getRange();
Range dstRange = dstAxis.getRange();
result = dstRange.getLowerBound() + ((source - srcRange.getLowerBound()) / srcRange.getLength()) * dstRange.getLength();
}
return result;
}
Regards,
Erik.