Open new frame or chart when a bar or a bar chart is clicked

后端 未结 1 1279
旧巷少年郎
旧巷少年郎 2021-01-25 07:33

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

相关标签:
1条回答
  • 2021-01-25 07:40

    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.

    image

    @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);
    }
    
    0 讨论(0)
提交回复
热议问题