我正在为我的最后一年的项目制作一个基于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图表,单击每个条形图或饼图以打开新框架或新图表
发布评论