Java Swing Clickable JFree图表,单击每个条形图或饼图以打开新框架或新图表

编程入门 行业动态 更新时间:2024-10-21 23:23:52
本文介绍了Java Swing Clickable JFree图表,单击每个条形图或饼图以打开新框架或新图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为我的最后一年的项目制作一个基于Java swing的桌面应用程序.我创建了从数据库连接的不同类型的图表.

I am making a desktop application based on java swing for my final year project. I have created different types of charts which is connected from my database.

现在想使此仪表板更具交互性,当单击每个条形时,我想进一步向下钻取以打开另一个图表或一个框架或表格以获取详细信息.

Now would like to make this dashboard more interactive and when click on the each bar i want to drill down further more to open another chart or maybe a frame or table for detailed information.

任何人都可以帮助我,如何单击图表上的条形以打开新框架或任何新窗口或图表?

Could anyone please help me how can i do to click a bar on the chart which opens a new frame or any new window or chart ?

下面是我的应用程序屏幕截图,也是我其中一张图表的代码.

Below is my screenshot of the application and also code of one of my charts.

谢谢大家

应用程序的屏幕截图

www.tiikoni/tis/view/?id = 3b425ff

www.tiikoni/tis/view/?id = 4336ceb

//For the Bar Chart private void lineChart() { // *************** ADDING BAR CHART FROM DATABASE ***************************** try { String sql = "select Region, Male, Female from ObeseLondon limit 14"; JDBCCategoryDataset dataset = new JDBCCategoryDataset(MySQL.Connectdb(), sql); JFreeChart chart = ChartFactory.createBarChart("", "Town", "No. Of Obese People", dataset, PlotOrientation.HORIZONTAL, true, true, true); chart.setBackgroundPaint(Color.white); BarRenderer render = null; //CategoryPlot plot = null; CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getRenderer().setSeriesPaint(0, Color.green); plot.getRenderer().setSeriesPaint(1, Color.yellow); render = new BarRenderer(); org.jfree.chart.ChartFrame chartframe = new org.jfree.chart.ChartFrame("Query Chart", chart); //chartframe.setVisible(true); //chartframe.setSize(200,500); panelBarChart.setLayout(new java.awt.BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); panelBarChart.add(chartPanel); panelBarChart.validate(); //****** Trying Button Click Action for bar chart ******** /* chart.addChangeListener(chartPanel); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent e) { } @Override public void chartMouseClicked(ChartMouseEvent e) { new JOptionPane().showMessageDialog(null, "You have clicked the bar chart", "Hello", JOptionPane.OK_OPTION); } }); */ } catch (Exception e) { JOptionPane.showMessageDialog(null, e); }

推荐答案

您需要在chartPanel中添加ChartMouseListener.

chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { ChartEntity entity = event.getEntity(); System.out.println(entity); } @Override public void chartMouseMoved(ChartMouseEvent event) { } });

ChartEntity将是一个CategoryItemEntity,可用于访问rowKey,columnKey和dataset.然后,您可以打开一个对话框或选项卡以显示找到的数据.

The ChartEntity will be a CategoryItemEntity that you can use to access the rowKey, columnKey and dataset. Then you can open a a dialog or tab to display the data found.

更多推荐

Java Swing Clickable JFree图表,单击每个条形图或饼图以打开新框架或新图表

本文发布于:2023-06-07 22:01:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图表   单击   开新   框架   或新

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!