I solved the issue with the wrong cursor label content.
Hope that someone adds the fix to the branch.
public void doPaint(Graphics2D g) {
//+++++
cursor.clearData();
//+++++
//+++++
import java.util.Arrays;
import java.util.Collections;
//+++++
//- - - - -
private void calculateMatchingDataPoints() {
List<DataPoint> dataPoints = new ArrayList<>();
for (DataPoint dataPoint : dataPointList) {
if (dataPoint.shape.contains(mouseX, dataPoint.shape.getBounds().getCenterY())
&& chart.plot.plotContent.getBounds().getY() < mouseY
&& chart.plot.plotContent.getBounds().getY()
+ chart.plot.plotContent.getBounds().getHeight()
> mouseY) {
dataPoints.add(dataPoint);
}
}
if (dataPoints.size() > 0) {
Map<String, DataPoint> map = new HashMap<>();
String seriesName = "";
for (DataPoint dataPoint : dataPoints) {
seriesName = dataPoint.seriesName;
if (map.containsKey(seriesName)) {
if (Math.abs(dataPoint.x - mouseX) < Math.abs(map.get(seriesName).x - mouseX)) {
map.put(seriesName, dataPoint);
}
} else {
map.put(seriesName, dataPoint);
}
}
matchingDataPointList.clear();
matchingDataPointList.addAll(map.values());
}
}
//- - - - -
//+++++
void clearData() {
dataPointList.clear();
}
//+++++
//+++++
private void calculateMatchingDataPoints() {
// find all points on y axis
List<DataPoint> dataPoints = new ArrayList<>();
for (DataPoint dataPoint : dataPointList) {
if (dataPoint.shape.contains(mouseX, dataPoint.shape.getBounds().getCenterY())
&& chart.plot.plotContent.getBounds().getY() < mouseY
&& chart.plot.plotContent.getBounds().getY() + chart.plot.plotContent.getBounds().getHeight() > mouseY) {
dataPoints.add(dataPoint);
}
}
if (dataPoints.size() > 0) {
// group data points by seriesName
// remove double values
Map<String, DataPoint> map = new HashMap<>();
HashMap<String, ArrayList<String>> sameSeriesPoints = new HashMap<String, ArrayList<String>>();
for (DataPoint dataPoint : dataPoints) {
String seriesName = dataPoint.seriesName;
DataPoint matchingPoint = map.get(seriesName);
if (matchingPoint == null) {
// first point of series
map.put(seriesName, dataPoint);
} else if ( !matchingPoint.yValue.equals(dataPoint.yValue) ) {
// another point of series
ArrayList<String> list = sameSeriesPoints.get(seriesName);
if ( list == null ) {
list = new ArrayList<String>();
sameSeriesPoints.put(seriesName, list);
}
// add only different values
if ( !list.contains(dataPoint.yValue) ) {
list.add(dataPoint.yValue);
}
}
}
if ( sameSeriesPoints.size() > 0 ) {
// create combined yValue
for ( String seriesName : sameSeriesPoints.keySet() ) {
DataPoint dp = map.get(seriesName);
// create sorted list
ArrayList<String> list = sameSeriesPoints.get(seriesName);
list.add(dp.yValue);
Collections.sort(list);
// build yValue String
StringBuilder sb = new StringBuilder();
boolean first = true;
for ( String s : list ) {
if ( !first ) {
sb.append(",");
}
first = false;
sb.append(s);
}
// replace DataPoint
map.put(seriesName, new DataPoint(dp.x, dp.y, dp.xValue, sb.toString(), seriesName));
}
}
matchingDataPointList.clear();
matchingDataPointList.addAll(map.values());
}
}
//+++++
I solved the issue with the wrong cursor label content.
Hope that someone adds the fix to the branch.
File: PlotContent_XY.java
File: Cursor.java
EDITED by @mccartney to fix the formatting