JFreeChart with selectable domain axis and zoom

You’ll have to combine several approaches: Panning controls: Invoke, setDomainPannable(true) to enable panning; in your controls, use panDomainAxes(), as shown in the implementation of mouseDragged(); use the mouse as suggested here. Zooming: Zooming by dragging on the axis is not supported, but dragging on the plot is supported; drag right to see the selection rectangle. … Read more

JFreeChart line chart with text at each point

The StandardXYItemLabelGenerator should work; there’s an example here. Addendum: The labels you can see in the picture are in a separate string array. Such labels may be incorporated in the XYDataset, as shown in LabeledXYDataset below. Because none of the features of StandardXYItemLabelGenerator are used, a custom implementation of XYItemLabelGenerator is sufficient. The XYItemRenderer controls … Read more

Displaying a histogram of image data

The example below uses several techniques to create an RGB histogram of an arbitrary image: The Raster method getSamples() extracts the values of each color band from the BufferedImage. The HistogramDataset method addSeries() adds each band’s counts to the dataset. A StandardXYBarPainter replaces the ChartFactory default, as shown here. A custom DefaultDrawingSupplier supplies the color … Read more

Changing mercury color in thermometer in JFreeChart

You may be looking for setSubrangePaint(), demonstrated below. import java.awt.Color; import java.awt.EventQueue; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.ThermometerPlot; import org.jfree.data.general.DefaultValueDataset; /** @see http://stackoverflow.com/questions/7597015 */ public class ThermometerDemo extends JPanel { private static final int W = 200; private static final int H = 2 * W; public ThermometerDemo(double value) … Read more

Using JFreeChart to display recent changes in a time series

The JFreeChart class DynamicTimeSeriesCollection is a good choice. Addendum: As noted by @Bahadır, the last point of the series was persistently zero. @Don helpfully suggests advancing the time and then appending the data. dataset.advanceTime(); dataset.appendData(newData); import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JPanel; import javax.swing.Timer; … Read more

JFreeChart MouseListener doesn’t resolve chart elements

Your exemplary renderer has the correct geometry when run from Swing, as shown below. I’m unsure why things are awry with SWT, but this result may narrow the search. import java.awt.Color; import java.awt.EventQueue; import java.awt.Paint; import java.util.Random; import javax.swing.JFrame; import org.jfree.chart.ChartMouseEvent; import org.jfree.chart.ChartMouseListener; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.DateTickMarkPosition; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.entity.ChartEntity; … Read more