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


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 axis bars, as I learned in a previous <a href="https://stackoverflow.com/q/28899094/230513" rel="nofollow">question</a>, but how do I set that when I click a particular bar on x or y axis and open a new frame or chart. Also an information box would be fine.

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(); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { ChartEntity entity = event.getEntity(); System.out.println(entity); } @Override public void chartMouseMoved(ChartMouseEvent event) { }


Open a JOptionPane in your handler, as shown below in a ChartMouseListener added to <a href="http://www.jfree.org/jfreechart/api/javadoc/src-html/org/jfree/chart/demo/BarChartDemo1.html" rel="nofollow">BarChartDemo1</a>. The pane displays a panel of labels, as shown in this related <a href="https://stackoverflow.com/a/3002830/230513" rel="nofollow">example</a>, but a nested ChartPanel would work as well.

<img alt="image" class="b-lazy" data-src="https://i.stack.imgur.com/0iaCj.png" data-original="https://i.stack.imgur.com/0iaCj.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

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


  • Open new frame or chart when a bar or a bar chart is clicked
  • How can Implenent a Pie Chart using jFreechart in jsp? [duplicate]
  • how to save image path to sql database in java
  • JFreeChart - IntervalMarker vertical?
  • How to to refresh the chart in ChartPanel class after loading the file?
  • jfreechart setbackgroundpaint not doing anything
  • ADODB Connection.ConnectionString property doesn't return server name
  • Retrieving data from database and displaying it by using ajax
  • How can JFreeChart print a scatter point directly on the x axis?
  • JFreechart color square grid on XY plot
  • Jfree chart change Y axis data
  • JFreeChart Dial chart in Coldfusion
  • Best java 3D pie chart API [closed]
  • Android PieChart Using AChartEngine
  • How to get selected elements of panels in JList (overlay selected elements)
  • How to use chart inside fragment in Android using Achartengine library?
  • Use JFuzzyLogic and android app
  • Free library supporting Gantt charts and granularity
  • React: Pass function to a child not working
  • Enabling/Disabling drawing of a JFreeChart
  • How to mock bean and avoiding NoUniqueBeanDefinitionException
  • SQL Compact Database larger than configured size
  • Unicode — What's going on here?
  • How to make a div to fit all available width even hidden with scroll?
  • Java Visualisation / Charting library like Google Charts / Visualisation
  • JFreeChart BarChart - Category Markers
  • JFreechart X and Y axis scaling
  • Stacked Bar Chart with percentage composition inside the Bar and total above the Bar in JFreeChart
  • JFreeChart & iText : black image when creating pdf
  • PHP multiple file uploads
  • PDO error when wrong host name
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • Limiting recursion to certain level - Duplicate rows
  • Moving mysql files across servers
  • Using $this when not in object context
  • How to check if every primary key value is being referenced as foreign key in another table
  • How to limit post in wp_query
  • Delete MySQLi record without showing the id in the URL
  • Comma separated Values
  • Hits per day in Google Big Query