JFreeChart is a comprehensive free chart library for the Java platform that enables developers to create professional-quality charts for both client-side and server-side applications with export capabilities to multiple formats including PNG and JPEG.
—
Plot management and customization for controlling visual appearance, axes, renderers, and plot-specific features. Plots are the core components that manage how data is displayed, providing extensive customization options for professional chart appearance.
Common functionality available to all plot types for managing appearance, backgrounds, and event handling.
/**
* Abstract base class for all plot types
*/
public abstract class Plot implements Drawable, Cloneable, PublicCloneable, Serializable {
// Background and appearance
public Paint getBackgroundPaint();
public void setBackgroundPaint(Paint paint);
public Image getBackgroundImage();
public void setBackgroundImage(Image image);
public RectangleInsets getInsets();
public void setInsets(RectangleInsets insets);
// Outline
public boolean isOutlineVisible();
public void setOutlineVisible(boolean visible);
public Stroke getOutlineStroke();
public void setOutlineStroke(Stroke stroke);
public Paint getOutlinePaint();
public void setOutlinePaint(Paint paint);
// Transparency
public float getForegroundAlpha();
public void setForegroundAlpha(float alpha);
public float getBackgroundAlpha();
public void setBackgroundAlpha(float alpha);
// Event handling
public void addChangeListener(PlotChangeListener listener);
public void removeChangeListener(PlotChangeListener listener);
// Abstract methods implemented by subclasses
public abstract void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info);
public abstract String getPlotType();
public abstract LegendItemCollection getLegendItems();
}Plot for displaying category-based data such as bar charts, line charts, and area charts. Manages datasets, axes, renderers, and category-specific features.
/**
* A plot for displaying data in categories (bar charts, line charts, etc.)
*/
public class CategoryPlot extends Plot implements ValueAxisPlot, Pannable, Zoomable, Cloneable {
// Dataset management
public CategoryDataset getDataset();
public CategoryDataset getDataset(int index);
public void setDataset(CategoryDataset dataset);
public void setDataset(int index, CategoryDataset dataset);
public int getDatasetCount();
public List getDatasets();
// Domain axis (categories)
public CategoryAxis getDomainAxis();
public CategoryAxis getDomainAxis(int index);
public void setDomainAxis(CategoryAxis axis);
public void setDomainAxis(int index, CategoryAxis axis);
public int getDomainAxisCount();
public List getDomainAxes();
// Range axis (values)
public ValueAxis getRangeAxis();
public ValueAxis getRangeAxis(int index);
public void setRangeAxis(ValueAxis axis);
public void setRangeAxis(int index, ValueAxis axis);
public int getRangeAxisCount();
public List getRangeAxes();
// Renderer management
public CategoryItemRenderer getRenderer();
public CategoryItemRenderer getRenderer(int index);
public void setRenderer(CategoryItemRenderer renderer);
public void setRenderer(int index, CategoryItemRenderer renderer);
public int getRendererCount();
public List getRenderers();
// Plot orientation
public PlotOrientation getOrientation();
public void setOrientation(PlotOrientation orientation);
// Axis positioning
public AxisLocation getDomainAxisLocation();
public AxisLocation getDomainAxisLocation(int index);
public void setDomainAxisLocation(AxisLocation location);
public void setDomainAxisLocation(int index, AxisLocation location, boolean notify);
public AxisLocation getRangeAxisLocation();
public AxisLocation getRangeAxisLocation(int index);
public void setRangeAxisLocation(AxisLocation location);
public void setRangeAxisLocation(int index, AxisLocation location, boolean notify);
// Gridlines
public boolean isDomainGridlinesVisible();
public void setDomainGridlinesVisible(boolean visible);
public Paint getDomainGridlinePaint();
public void setDomainGridlinePaint(Paint paint);
public Stroke getDomainGridlineStroke();
public void setDomainGridlineStroke(Stroke stroke);
public boolean isRangeGridlinesVisible();
public void setRangeGridlinesVisible(boolean visible);
public Paint getRangeGridlinePaint();
public void setRangeGridlinePaint(Paint paint);
public Stroke getRangeGridlineStroke();
public void setRangeGridlineStroke(Stroke stroke);
// Markers and annotations
public void addRangeMarker(Marker marker);
public void addRangeMarker(int index, Marker marker, Layer layer);
public void clearRangeMarkers();
public void addDomainMarker(CategoryMarker marker);
public void addDomainMarker(int index, CategoryMarker marker, Layer layer);
public void clearDomainMarkers();
public void addAnnotation(CategoryAnnotation annotation);
public void removeAnnotation(CategoryAnnotation annotation);
public List getAnnotations();
}Usage Example:
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.category.*;
// Get the plot from a chart
JFreeChart chart = ChartFactory.createBarChart(
"Sales", "Month", "Revenue", dataset);
CategoryPlot plot = chart.getCategoryPlot();
// Customize appearance
plot.setBackgroundPaint(Color.LIGHT_GRAY);
plot.setRangeGridlinePaint(Color.WHITE);
plot.setRangeGridlinesVisible(true);
// Customize renderer
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setSeriesPaint(0, Color.BLUE);
renderer.setSeriesOutlinePaint(0, Color.BLACK);
renderer.setDrawBarOutline(true);
// Add range marker
ValueMarker marker = new ValueMarker(100.0);
marker.setPaint(Color.RED);
marker.setLabel("Target");
plot.addRangeMarker(marker);Plot for displaying XY coordinate data such as scatter plots, line charts, and time series. Supports continuous data with numeric axes.
/**
* A plot for displaying XY data (scatter plots, time series, etc.)
*/
public class XYPlot extends Plot implements ValueAxisPlot, Pannable, Zoomable, Cloneable {
// Dataset management
public XYDataset getDataset();
public XYDataset getDataset(int index);
public void setDataset(XYDataset dataset);
public void setDataset(int index, XYDataset dataset);
public int getDatasetCount();
public List getDatasets();
// Domain axis (X axis)
public ValueAxis getDomainAxis();
public ValueAxis getDomainAxis(int index);
public void setDomainAxis(ValueAxis axis);
public void setDomainAxis(int index, ValueAxis axis);
public int getDomainAxisCount();
public List getDomainAxes();
// Range axis (Y axis)
public ValueAxis getRangeAxis();
public ValueAxis getRangeAxis(int index);
public void setRangeAxis(ValueAxis axis);
public void setRangeAxis(int index, ValueAxis axis);
public int getRangeAxisCount();
public List getRangeAxes();
// Renderer management
public XYItemRenderer getRenderer();
public XYItemRenderer getRenderer(int index);
public void setRenderer(XYItemRenderer renderer);
public void setRenderer(int index, XYItemRenderer renderer);
public int getRendererCount();
public List getRenderers();
// Plot orientation
public PlotOrientation getOrientation();
public void setOrientation(PlotOrientation orientation);
// Axis positioning
public AxisLocation getDomainAxisLocation();
public AxisLocation getDomainAxisLocation(int index);
public void setDomainAxisLocation(AxisLocation location);
public void setDomainAxisLocation(int index, AxisLocation location);
public AxisLocation getRangeAxisLocation();
public AxisLocation getRangeAxisLocation(int index);
public void setRangeAxisLocation(AxisLocation location);
public void setRangeAxisLocation(int index, AxisLocation location);
// Gridlines
public boolean isDomainGridlinesVisible();
public void setDomainGridlinesVisible(boolean visible);
public Paint getDomainGridlinePaint();
public void setDomainGridlinePaint(Paint paint);
public Stroke getDomainGridlineStroke();
public void setDomainGridlineStroke(Stroke stroke);
public boolean isDomainMinorGridlinesVisible();
public void setDomainMinorGridlinesVisible(boolean visible);
public boolean isRangeGridlinesVisible();
public void setRangeGridlinesVisible(boolean visible);
public Paint getRangeGridlinePaint();
public void setRangeGridlinePaint(Paint paint);
public Stroke getRangeGridlineStroke();
public void setRangeGridlineStroke(Stroke stroke);
public boolean isRangeMinorGridlinesVisible();
public void setRangeMinorGridlinesVisible(boolean visible);
// Zero baselines
public boolean isDomainZeroBaselineVisible();
public void setDomainZeroBaselineVisible(boolean visible);
public boolean isRangeZeroBaselineVisible();
public void setRangeZeroBaselineVisible(boolean visible);
// Markers and annotations
public void addRangeMarker(Marker marker);
public void addRangeMarker(int index, Marker marker, Layer layer);
public void clearRangeMarkers();
public void addDomainMarker(ValueMarker marker);
public void addDomainMarker(int index, ValueMarker marker, Layer layer);
public void clearDomainMarkers();
public void addAnnotation(XYAnnotation annotation);
public void removeAnnotation(XYAnnotation annotation);
public List getAnnotations();
}Usage Example:
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.xy.*;
// Get the plot from a chart
JFreeChart chart = ChartFactory.createXYLineChart(
"Temperature", "Time", "°C", dataset);
XYPlot plot = (XYPlot) chart.getPlot();
// Customize appearance
plot.setBackgroundPaint(Color.WHITE);
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
// Customize renderer
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesPaint(0, Color.RED);
renderer.setSeriesStroke(0, new BasicStroke(2.0f));
renderer.setSeriesShapesVisible(0, true);
plot.setRenderer(renderer);
// Add domain marker for specific time
ValueMarker timeMarker = new ValueMarker(System.currentTimeMillis());
timeMarker.setPaint(Color.BLUE);
timeMarker.setLabel("Current Time");
plot.addDomainMarker(timeMarker);Plot for displaying pie chart data showing proportional relationships between categories.
/**
* A plot for displaying pie chart data
*/
public class PiePlot<K> extends Plot implements Cloneable {
// Dataset management
public PieDataset<K> getDataset();
public void setDataset(PieDataset<K> dataset);
// Label generation
public PieSectionLabelGenerator getLabelGenerator();
public void setLabelGenerator(PieSectionLabelGenerator generator);
public boolean getLabelsVisible();
public void setLabelsVisible(boolean visible);
public Font getLabelFont();
public void setLabelFont(Font font);
public Paint getLabelPaint();
public void setLabelPaint(Paint paint);
// Tooltip and URL generation
public PieToolTipGenerator getToolTipGenerator();
public void setToolTipGenerator(PieToolTipGenerator generator);
public PieURLGenerator getURLGenerator();
public void setURLGenerator(PieURLGenerator generator);
// Section appearance
public Paint getSectionPaint(K key);
public void setSectionPaint(K key, Paint paint);
public void clearSectionPaints(boolean notify);
public Paint getSectionOutlinePaint(K key);
public void setSectionOutlinePaint(K key, Paint paint);
public void clearSectionOutlinePaints(boolean notify);
public Stroke getSectionOutlineStroke(K key);
public void setSectionOutlineStroke(K key, Stroke stroke);
public void clearSectionOutlineStrokes(boolean notify);
public boolean getSectionOutlinesVisible();
public void setSectionOutlinesVisible(boolean visible);
// Pie appearance
public double getStartAngle();
public void setStartAngle(double angle);
public Rotation getDirection();
public void setDirection(Rotation direction);
public double getInteriorGap();
public void setInteriorGap(double percent);
public boolean getCircular();
public void setCircular(boolean flag);
// Data handling
public double getMinimumArcAngleToDraw();
public void setMinimumArcAngleToDraw(double angle);
public boolean isIgnoreNullValues();
public void setIgnoreNullValues(boolean flag);
public boolean isIgnoreZeroValues();
public void setIgnoreZeroValues(boolean flag);
}Usage Example:
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
// Get the plot from a pie chart
JFreeChart chart = ChartFactory.createPieChart(
"Market Share", dataset);
PiePlot plot = (PiePlot) chart.getPlot();
// Customize appearance
plot.setStartAngle(90);
plot.setDirection(Rotation.CLOCKWISE);
plot.setInteriorGap(0.05);
plot.setSectionOutlinesVisible(true);
// Customize individual sections
plot.setSectionPaint("Chrome", Color.BLUE);
plot.setSectionPaint("Firefox", Color.ORANGE);
plot.setSectionPaint("Safari", Color.GRAY);
// Set explode factor for specific section
plot.setExplodePercent("Chrome", 0.10);
// Hide small sections
plot.setMinimumArcAngleToDraw(0.02); // 2% minimum
plot.setIgnoreZeroValues(true);Support for complex charts with multiple datasets, axes, and renderers.
// CategoryPlot multi-dataset methods
public void mapDatasetToDomainAxis(int index, int axisIndex);
public void mapDatasetToRangeAxis(int index, int axisIndex);
public int getDomainAxisIndex(CategoryAxis axis);
public int getRangeAxisIndex(ValueAxis axis);
// XYPlot multi-dataset methods
public void mapDatasetToDomainAxis(int index, int axisIndex);
public void mapDatasetToRangeAxis(int index, int axisIndex);
public int getDomainAxisIndex(ValueAxis axis);
public int getRangeAxisIndex(ValueAxis axis);
// Renderer mapping
public CategoryItemRenderer getRendererForDataset(CategoryDataset dataset);
public XYItemRenderer getRendererForDataset(XYDataset dataset);Usage Example:
// Create plot with multiple datasets and axes
CategoryPlot plot = new CategoryPlot();
// Add primary dataset and axis
plot.setDataset(0, primaryDataset);
plot.setRangeAxis(0, new NumberAxis("Primary Values"));
// Add secondary dataset and axis
plot.setDataset(1, secondaryDataset);
plot.setRangeAxis(1, new NumberAxis("Secondary Values"));
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
// Map datasets to axes
plot.mapDatasetToRangeAxis(0, 0); // Primary dataset to primary axis
plot.mapDatasetToRangeAxis(1, 1); // Secondary dataset to secondary axis
// Set different renderers
plot.setRenderer(0, new BarRenderer());
plot.setRenderer(1, new LineAndShapeRenderer());Additional plot functionality for specialized use cases and advanced customization.
// Crosshair support (XYPlot)
public boolean isDomainCrosshairVisible();
public void setDomainCrosshairVisible(boolean flag);
public double getDomainCrosshairValue();
public void setDomainCrosshairValue(double value);
public boolean isRangeCrosshairVisible();
public void setRangeCrosshairVisible(boolean flag);
public double getRangeCrosshairValue();
public void setRangeCrosshairValue(double value);
// Zooming and panning support
public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source);
public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source);
public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source);
public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source);
public void panDomainAxes(double percent, PlotRenderingInfo info, Point2D source);
public void panRangeAxes(double percent, PlotRenderingInfo info, Point2D source);
// Drawing supplier for consistent colors/shapes across renderers
public DrawingSupplier getDrawingSupplier();
public void setDrawingSupplier(DrawingSupplier supplier);
// Dataset ordering for CategoryPlot
public DatasetRenderingOrder getDatasetRenderingOrder();
public void setDatasetRenderingOrder(DatasetRenderingOrder order);
// Series rendering order for CategoryPlot
public SortOrder getColumnRenderingOrder();
public void setColumnRenderingOrder(SortOrder order);
public SortOrder getRowRenderingOrder();
public void setRowRenderingOrder(SortOrder order);Usage Example:
// Enable crosshairs on XY plot
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
plot.setDomainCrosshairPaint(Color.RED);
plot.setRangeCrosshairPaint(Color.RED);
// Configure zooming
plot.setDomainZoomable(true);
plot.setRangeZoomable(true);
// Set rendering order for multiple datasets
CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
categoryPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
categoryPlot.setRowRenderingOrder(SortOrder.ASCENDING);Install with Tessl CLI
npx tessl i tessl/maven-org-jfree--jfreechart