Jfree chart Find Subplot

You can get a List of subplots using getSubplots(). To learn which subplot was clicked, examine the ChartMouseEvent that was sent from the ChartPanel, as suggested here. Addendum: Here’s a simple implementation of ChartMouseListener that will show each ChartEntity as it is clicked. ChartPanel panel = … panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) … Read more

How to use SwingWorker?

SwingWorker is a lot simpler to use them it might seem. Basically, you need to make a few basic decisions about what you want to achieve. Do you want to return periodically updates while the process is running or Do you want to return a result of the process…or both? Do you want to provide … Read more

Read data from CSV file into ArrayList and display in XY Chart

Several problems are evident: You never add anything to lines; at a minimum, you’ll need something like this: lines.add(line); Instead of ChartFactory.createXYLineChart(), consider creating a time series: ChartFactory.createTimeSeriesChart(…) The XYDataset returned by createDataset() should be a TimeSeriesCollection to which you add a TimeSeries. In createDataset(), iterate though lines, parse the data fields, and add the … Read more

JFreeChart BarChart -> NO gradient

The problem lies in the BarPainter you are using. The JFreeChart version 1.0.13 default is to use GradientBarPainter which adds a metallic-ish look to the bar. If you want the “old” look the solution is to use the StandardBarPainter. final CategoryPlot plot = chart.getCategoryPlot(); ((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter()); That should do it. Alternatively, if you want … Read more

Setting Range for X,Y Axis-JfreeChart

I’m guessing your new NumberAxis instances aren’t being used by the plot; it may be easier to use the existing ones from the factory. import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.util.*; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import org.jfree.chart.*; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import … Read more

Abnormal Behaviour of the Zoom In and Zoom Out Functionality of the JFreeChart?

Your example appears to be mixing the two approaches suggested here, invoking the chart panel’s handler from within your own actionPerformed() implementation. While the chart panel handlers are reusable, they are not re-entrant. Instead, use the chart panel’s implementation directly. The example below focuses on two buttons to zoom the domain in and out: toolBar.add(createButton(“Zoom … Read more