I have a bar chart which gets the dataset from the mysql database, and I am stuck on using the chartMouseClicked
. Currently the code prints when clicked on x or y a
Open a JOptionPane
in your handler, as shown below in a ChartMouseListener
added to BarChartDemo1. The pane displays a panel of labels, as shown in this related example, but a nested ChartPanel
would work as well.
@Override
public void chartMouseClicked(ChartMouseEvent event) {
CategoryItemEntity entity = (CategoryItemEntity) event.getEntity();
JPanel panel = new JPanel(new GridLayout(0, 1));
Comparable row = entity.getRowKey();
Comparable col = entity.getColumnKey();
panel.add(new JLabel(String.valueOf(row)));
panel.add(new JLabel(String.valueOf(col)));
panel.add(new JLabel(String.valueOf(entity.getDataset().getValue(row, col))));
JOptionPane.showMessageDialog(rootPane, panel);
}