Insert a button into a JFreeChart graph

后端 未结 2 480
有刺的猬
有刺的猬 2021-01-23 01:21

I used a code in order to display a graph. I want to insert a button in this graph (Show details) that i will used in order to present some details about the graph .It is realis

2条回答
  •  遥遥无期
    2021-01-23 01:55

    Add a ChartMouseListener to the ChartPanel that contains your chart. You can get details about the PieSectionEntity that was clicked as shown below. See the implementation of toString() in PieSectionEntity for more. Optionally, you can highlight the entity as shown here.

    ChartPanel panel = new ChartPanel(chart);
    panel.addChartMouseListener(new ChartMouseListener() {
    
        @Override
        public void chartMouseClicked(ChartMouseEvent e) {
            ChartEntity entity = e.getEntity();
            if (entity instanceof PieSectionEntity) {
                PieSectionEntity pse = (PieSectionEntity) entity;
                System.out.println(pse);
            }
        }
    
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });
    

提交回复
热议问题