Replies: 2 comments
-
|
I understand now. 🙇 @Override
public void chartMouseMoved(ChartMouseEvent event) {
Rectangle2D dataArea = panel.getScreenDataArea();
JFreeChart chart = event.getChart();
XYPlot plot = (XYPlot)chart.getPlot();
// X
ValueAxis xAxis = plot.getDomainAxis();
double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
xCrosshair.setValue(x);
// Y
Map<Integer, XYDataset> datasets = plot.getDatasets();
Set<Entry<Integer, XYDataset>> entrySet = datasets.entrySet();
Iterator<Entry<Integer, XYDataset>> iterator = entrySet.iterator();
Entry<Integer, XYDataset> mainAxisEntry = iterator.next();
Integer mainIndex = mainAxisEntry.getKey();
XYDataset mainDataSet = mainAxisEntry.getValue();
double mainValY = DatasetUtils.findYValue(mainDataSet, 0, x);
yCrosshairs[mainIndex].setValue(mainValY);
RectangleEdge mainRangeAxisEdge = plot.getRangeAxisEdge(0);
ValueAxis mainRangeAxis = plot.getRangeAxis(0);
while(iterator.hasNext()) {
Entry<Integer, XYDataset> childRangeAxis = iterator.next();
XYDataset value = childRangeAxis.getValue();
Integer key = childRangeAxis.getKey();
double y = DatasetUtils.findYValue(value, 0, x);
ValueAxis rangeAxis = plot.getRangeAxis(key);
double valueToJava = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge(key));
double transformY = mainRangeAxis.java2DToValue(valueToJava, dataArea, mainRangeAxisEdge);
yCrosshairs[key].setValue(transformY);
yCrosshairs[key].setLabelGenerator(ch -> {
return numberFormat.format(y);
});
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
-
|
As you have found, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How to correctly use Crosshair and CrosshairOverlay when there are multiple RangeAxes in JFreeChart? I would like to get your explanation.
As shown in the image, the Crosshair for I1 retrieves the correct value, but its position is incorrect.

SocketDataComposite.java
Beta Was this translation helpful? Give feedback.
All reactions