将按钮插入JFreeChart图形 [英] Insert a button into a JFreeChart graph

查看:245
本文介绍了将按钮插入JFreeChart图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用代码为了显示图表。
我想在这个图形(显示详细信息)中插入一个按钮,我将使用它来呈现图形的一些细节。它是可实现的?
谢谢。

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 realisable? thanks.

if(jCheckBox3.isSelected()) {
    try {
        con = getConnection("jdbc:mysql://localhost:3306/base_rapport","root","");
        Statement statement = con.createStatement(rs.TYPE_FORWARD_ONLY,rs.CONCUR_READ_ONLY);
        String sql3 = "Select Vendor, sum(Rate) as Rate from (select case Vendor when 'NSN' then 'Nokia' else Vendor end as Vendor, Rate from  (  Select vendor ,(count(1) )*100/(Select count(id_incident)from incident where open_time between '"+jTextField1.getText()+"' and'"+jTextField2.getText()+"' and vendor !='') as Rate  from incident   where open_time between '"+jTextField1.getText()+"'and'"+jTextField2.getText()+"' and vendor !='' group by upper(vendor) ) as x ) as y group by vendor";

        rs3 = statement.executeQuery(sql3);
        DefaultPieDataset pieDataset = new DefaultPieDataset(); 

        while(rs3.next()) {      
            pieDataset.setValue( rs3.getString("vendor"),rs3.getDouble(2));
        }

        JFreeChart chart = ChartFactory.createPieChart3D("Disfonctionnement par fournisseurs",  pieDataset, true, true, true); 
        PiePlot3D piePlot3d = (PiePlot3D) chart.getPlot();
        piePlot3d.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}"));
        fenetre fen3 = new fenetre();
        JPanel pnl = new JPanel(new BorderLayout()); 

        fen3.setContentPane(pnl); 
        fen3.setVisible(true);
        fen3.setSize(500, 500); 
        ChartPanel cPanel1 = new ChartPanel(chart);    
        pnl.add(cPanel1);
        File fichier = new File("C:\\Users\\alaeddine.zammeli.st\\Desktop\\résultat_application\\Répartition par fournisseur de '"+jTextField1.getText()+"' à '"+jTextField2.getText()+"'.png");

        try { 
            ChartUtilities.saveChartAsPNG(fichier, chart, 500, 500); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this,e);
    }
}


推荐答案

a ChartMouseListener 到包含图表的 ChartPanel 。您可以获得有关点击的 PieSectionEntity 的详细信息,如下所示。请参阅 toString() PieSectionEntity 中的实现。您也可以选择突出显示此处所示的实体。

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) {
    }
});

这篇关于将按钮插入JFreeChart图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆