Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listener For Mouse Over On Chart Element #520

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void mouseDragged(MouseEvent e) {
// ignore
}


@Override
public void mouseMoved(MouseEvent e) {

Expand Down Expand Up @@ -89,6 +90,21 @@ else if (dataPoint != null) {
dataPoint = null;
e.getComponent().repaint(); // repaint the entire XChartPanel
}

/*This loop checks the X position of the mouse in the chart, and runs through
* the datapoints to determine if the user is hovering over anything. If so,
* a datapoints information can be displayed however a user sees fit.
* This could be built on in the future with a custom UI for the info
*
* chart.getStyler().setToolTipsEnabled(true); must be enabled in your chart. */
for (DataPoint dataPoint : dataPointList) {
Integer result = Integer.compare((int) dataPoint.x, e.getX());
if (result == 0) {
System.out.println(dataPoint.label);
//This is an execution point for when the mouse is over a datapoint.
}
}

}

void prepare(Graphics2D g) {
Expand Down