CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jfree--jfreechart

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.

Pending
Overview
Eval results
Files

rendering-styling.mddocs/

Rendering and Styling

Renderer interfaces and implementations that control how data is visually represented. Renderers are responsible for drawing data items, managing colors, shapes, strokes, and providing interactive features like tooltips and item labels.

Capabilities

Category Item Renderers

Renderers for category-based charts that control how data items are drawn in CategoryPlot.

/**
 * Interface for rendering items in category plots
 */
public interface CategoryItemRenderer extends LegendItemSource {
    /**
     * Returns the number of passes required by the renderer
     * @return the pass count
     */
    public int getPassCount();
    
    /**
     * Returns the plot that the renderer is assigned to
     * @return the plot
     */
    public CategoryPlot getPlot();
    
    /**
     * Sets the plot that the renderer is assigned to
     * @param plot the plot
     */
    public void setPlot(CategoryPlot plot);
    
    /**
     * Draws a single data item
     * @param g2 the graphics device
     * @param state the renderer state
     * @param dataArea the area within which the data is being drawn
     * @param plot the plot (can be used to obtain standard color information etc)
     * @param domainAxis the domain axis
     * @param rangeAxis the range axis
     * @param dataset the dataset
     * @param row the row index (zero-based)
     * @param column the column index (zero-based)
     * @param pass the pass index
     */
    public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass);
    
    // Visibility control
    public boolean getItemVisible(int series, int item);
    public Boolean getSeriesVisible(int series);
    public void setSeriesVisible(int series, Boolean visible);
    public Boolean getSeriesVisibleInLegend(int series);
    public void setSeriesVisibleInLegend(int series, Boolean visible);
    public boolean getDefaultSeriesVisible();
    public void setDefaultSeriesVisible(boolean visible);
    
    // Paint (color) control
    public Paint getItemPaint(int row, int column);
    public Paint getSeriesPaint(int series);
    public void setSeriesPaint(int series, Paint paint);
    public Paint getDefaultPaint();
    public void setDefaultPaint(Paint paint);
    
    // Outline paint control
    public Paint getItemOutlinePaint(int row, int column);
    public Paint getSeriesOutlinePaint(int series);
    public void setSeriesOutlinePaint(int series, Paint paint);
    public Paint getDefaultOutlinePaint();
    public void setDefaultOutlinePaint(Paint paint);
    
    // Stroke control
    public Stroke getItemStroke(int row, int column);
    public Stroke getSeriesStroke(int series);
    public void setSeriesStroke(int series, Stroke stroke);
    public Stroke getDefaultStroke();
    public void setDefaultStroke(Stroke stroke);
    
    // Outline stroke control
    public Stroke getItemOutlineStroke(int row, int column);
    public Stroke getSeriesOutlineStroke(int series);
    public void setSeriesOutlineStroke(int series, Stroke stroke);
    public Stroke getDefaultOutlineStroke();
    public void setDefaultOutlineStroke(Stroke stroke);
    
    // Shape control
    public Shape getItemShape(int row, int column);
    public Shape getSeriesShape(int series);
    public void setSeriesShape(int series, Shape shape);
    public Shape getDefaultShape();
    public void setDefaultShape(Shape shape);
    
    // Item label control
    public boolean getItemLabelVisible(int series, int item);
    public Boolean getSeriesItemLabelsVisible(int series);
    public void setSeriesItemLabelsVisible(int series, Boolean visible);
    public boolean getDefaultItemLabelsVisible();
    public void setDefaultItemLabelsVisible(boolean visible);
    
    // Label generators and positioning
    public CategoryItemLabelGenerator getItemLabelGenerator(int row, int column);
    public CategoryItemLabelGenerator getSeriesItemLabelGenerator(int series);
    public void setSeriesItemLabelGenerator(int series, CategoryItemLabelGenerator generator);
    public CategoryItemLabelGenerator getDefaultItemLabelGenerator();
    public void setDefaultItemLabelGenerator(CategoryItemLabelGenerator generator);
    
    public ItemLabelPosition getPositiveItemLabelPosition(int row, int column);
    public ItemLabelPosition getSeriesPositiveItemLabelPosition(int series);
    public void setSeriesPositiveItemLabelPosition(int series, ItemLabelPosition position);
    public ItemLabelPosition getDefaultPositiveItemLabelPosition();
    public void setDefaultPositiveItemLabelPosition(ItemLabelPosition position);
    
    public ItemLabelPosition getNegativeItemLabelPosition(int row, int column);
    public ItemLabelPosition getSeriesNegativeItemLabelPosition(int series);
    public void setSeriesNegativeItemLabelPosition(int series, ItemLabelPosition position);
    public ItemLabelPosition getDefaultNegativeItemLabelPosition();
    public void setDefaultNegativeItemLabelPosition(ItemLabelPosition position);
    
    // Tooltip control
    public CategoryToolTipGenerator getToolTipGenerator(int row, int column);
    public CategoryToolTipGenerator getSeriesToolTipGenerator(int series);
    public void setSeriesToolTipGenerator(int series, CategoryToolTipGenerator generator);
    public CategoryToolTipGenerator getDefaultToolTipGenerator();
    public void setDefaultToolTipGenerator(CategoryToolTipGenerator generator);
    
    // URL control
    public CategoryURLGenerator getItemURLGenerator(int row, int column);
    public CategoryURLGenerator getSeriesItemURLGenerator(int series);
    public void setSeriesItemURLGenerator(int series, CategoryURLGenerator generator);
    public CategoryURLGenerator getDefaultItemURLGenerator();
    public void setDefaultItemURLGenerator(CategoryURLGenerator generator);
}

/**
 * Standard bar chart renderer
 */
public class BarRenderer extends AbstractCategoryItemRenderer {
    /**
     * Creates a new bar renderer
     */
    public BarRenderer();
    
    // Bar appearance
    public double getItemMargin();
    public void setItemMargin(double percent);
    public boolean getDrawBarOutline();
    public void setDrawBarOutline(boolean draw);
    public double getMaximumBarWidth();
    public void setMaximumBarWidth(double percent);
    public double getMinimumBarLength();
    public void setMinimumBarLength(double length);
    public GradientPaintTransformer getGradientPaintTransformer();
    public void setGradientPaintTransformer(GradientPaintTransformer transformer);
    
    // Shadows and 3D effects
    public boolean getShadowsVisible();
    public void setShadowsVisible(boolean visible);
    public Paint getShadowPaint();
    public void setShadowPaint(Paint paint);
    public double getShadowXOffset();
    public void setShadowXOffset(double offset);
    public double getShadowYOffset();
    public void setShadowYOffset(double offset);
    
    // Base value
    public double getBase();
    public void setBase(double base);
    public boolean getIncludeBaseInRange();
    public void setIncludeBaseInRange(boolean include);
}

/**
 * Stacked bar chart renderer
 */
public class StackedBarRenderer extends BarRenderer {
    /**
     * Creates a new stacked bar renderer
     */
    public StackedBarRenderer();
    
    /**
     * Creates a new stacked bar renderer with percentage display option
     * @param renderAsPercentages flag to render values as percentages
     */
    public StackedBarRenderer(boolean renderAsPercentages);
    
    public boolean getRenderAsPercentages();
    public void setRenderAsPercentages(boolean asPercentages);
}

/**
 * Line and shape renderer for category plots
 */
public class LineAndShapeRenderer extends AbstractCategoryItemRenderer {
    /**
     * Creates a new line and shape renderer
     */
    public LineAndShapeRenderer();
    
    /**
     * Creates a new line and shape renderer with display options
     * @param lines flag to draw lines between points
     * @param shapes flag to draw shapes at data points
     */
    public LineAndShapeRenderer(boolean lines, boolean shapes);
    
    // Line visibility
    public Boolean getSeriesLinesVisible(int series);
    public void setSeriesLinesVisible(int series, Boolean flag);
    public boolean getDefaultLinesVisible();
    public void setDefaultLinesVisible(boolean flag);
    
    // Shape visibility
    public Boolean getSeriesShapesVisible(int series);
    public void setSeriesShapesVisible(int series, Boolean flag);
    public boolean getDefaultShapesVisible();
    public void setDefaultShapesVisible(boolean flag);
    
    // Shape filling
    public Boolean getSeriesShapesFilled(int series);
    public void setSeriesShapesFilled(int series, Boolean flag);
    public boolean getDefaultShapesFilled();
    public void setDefaultShapesFilled(boolean flag);
    
    // Advanced line drawing
    public boolean getDrawOutlines();
    public void setDrawOutlines(boolean flag);
    public boolean getUseOutlinePaint();
    public void setUseOutlinePaint(boolean use);
    public boolean getUseFillPaint();
    public void setUseFillPaint(boolean use);
}

Usage Example:

import org.jfree.chart.renderer.category.*;
import java.awt.*;

// Customize bar renderer
CategoryPlot plot = chart.getCategoryPlot();
BarRenderer renderer = (BarRenderer) plot.getRenderer();

// Set colors for different series
renderer.setSeriesPaint(0, Color.BLUE);
renderer.setSeriesPaint(1, Color.RED);
renderer.setSeriesPaint(2, Color.GREEN);

// Configure bar appearance
renderer.setItemMargin(0.1);           // 10% margin between items
renderer.setDrawBarOutline(true);      // Draw outlines around bars
renderer.setSeriesOutlinePaint(0, Color.BLACK);
renderer.setMaximumBarWidth(0.8);      // Maximum 80% of available space

// Enable shadows
renderer.setShadowsVisible(true);
renderer.setShadowPaint(Color.GRAY);
renderer.setShadowXOffset(2.0);
renderer.setShadowYOffset(2.0);

// Configure item labels
renderer.setDefaultItemLabelsVisible(true);
renderer.setDefaultItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setDefaultPositiveItemLabelPosition(
    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));

XY Item Renderers

Renderers for XY plots that control how data points are drawn in scatter plots, line charts, and time series.

/**
 * Interface for rendering items in XY plots
 */
public interface XYItemRenderer extends LegendItemSource {
    /**
     * Returns the number of passes required by the renderer
     * @return the pass count
     */
    public int getPassCount();
    
    /**
     * Returns the plot that the renderer is assigned to
     * @return the plot
     */
    public XYPlot getPlot();
    
    /**
     * Sets the plot that the renderer is assigned to
     * @param plot the plot
     */
    public void setPlot(XYPlot plot);
    
    /**
     * Draws a single data item
     * @param g2 the graphics device
     * @param state the renderer state
     * @param dataArea the area within which the data is being drawn
     * @param info collects plot rendering info
     * @param plot the plot (can be used to obtain standard color information etc)
     * @param domainAxis the domain axis
     * @param rangeAxis the range axis
     * @param dataset the dataset
     * @param series the series index (zero-based)
     * @param item the item index (zero-based)
     * @param crosshairState crosshair information for the plot
     * @param pass the pass index
     */
    public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass);
    
    // Grid band filling
    public void fillDomainGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double start, double end);
    public void fillRangeGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double start, double end);
    
    // Visibility control (similar to CategoryItemRenderer)
    public boolean getItemVisible(int series, int item);
    public Boolean getSeriesVisible(int series);
    public void setSeriesVisible(int series, Boolean visible);
    public boolean getDefaultSeriesVisible();
    public void setDefaultSeriesVisible(boolean visible);
    
    // Paint control
    public Paint getItemPaint(int series, int item);
    public Paint getSeriesPaint(int series);
    public void setSeriesPaint(int series, Paint paint);
    public Paint getDefaultPaint();
    public void setDefaultPaint(Paint paint);
    
    // Stroke control
    public Stroke getItemStroke(int series, int item);
    public Stroke getSeriesStroke(int series);
    public void setSeriesStroke(int series, Stroke stroke);
    public Stroke getDefaultStroke();
    public void setDefaultStroke(Stroke stroke);
    
    // Shape control
    public Shape getItemShape(int series, int item);
    public Shape getSeriesShape(int series);
    public void setSeriesShape(int series, Shape shape);
    public Shape getDefaultShape();
    public void setDefaultShape(Shape shape);
    
    // Item label control
    public XYItemLabelGenerator getItemLabelGenerator(int series, int item);
    public XYItemLabelGenerator getSeriesItemLabelGenerator(int series);
    public void setSeriesItemLabelGenerator(int series, XYItemLabelGenerator generator);
    public XYItemLabelGenerator getDefaultItemLabelGenerator();
    public void setDefaultItemLabelGenerator(XYItemLabelGenerator generator);
    
    // Tooltip control
    public XYToolTipGenerator getToolTipGenerator(int series, int item);
    public XYToolTipGenerator getSeriesToolTipGenerator(int series);
    public void setSeriesToolTipGenerator(int series, XYToolTipGenerator generator);
    public XYToolTipGenerator getDefaultToolTipGenerator();
    public void setDefaultToolTipGenerator(XYToolTipGenerator generator);
    
    // URL control
    public XYURLGenerator getURLGenerator();
    public void setURLGenerator(XYURLGenerator urlGenerator);
}

/**
 * Line and shape renderer for XY plots
 */
public class XYLineAndShapeRenderer extends AbstractXYItemRenderer {
    /**
     * Creates a new XY line and shape renderer
     */
    public XYLineAndShapeRenderer();
    
    /**
     * Creates a new XY line and shape renderer with display options
     * @param lines flag to draw lines between points
     * @param shapes flag to draw shapes at data points
     */
    public XYLineAndShapeRenderer(boolean lines, boolean shapes);
    
    // Line visibility
    public Boolean getSeriesLinesVisible(int series);
    public void setSeriesLinesVisible(int series, Boolean flag);
    public boolean getDefaultLinesVisible();
    public void setDefaultLinesVisible(boolean flag);
    
    // Shape visibility  
    public Boolean getSeriesShapesVisible(int series);
    public void setSeriesShapesVisible(int series, Boolean flag);
    public boolean getDefaultShapesVisible();
    public void setDefaultShapesVisible(boolean flag);
    
    // Shape filling
    public Boolean getSeriesShapesFilled(int series);
    public void setSeriesShapesFilled(int series, Boolean flag);
    public boolean getDefaultShapesFilled();
    public void setDefaultShapesFilled(boolean flag);
    
    // Advanced drawing options
    public boolean getDrawOutlines();
    public void setDrawOutlines(boolean flag);
    public boolean getDrawSeriesLineAsPath();
    public void setDrawSeriesLineAsPath(boolean flag);
}

/**
 * Area renderer for XY plots
 */
public class XYAreaRenderer extends AbstractXYItemRenderer {
    public static final int SHAPES = 1;
    public static final int LINES = 2;
    public static final int SHAPES_AND_LINES = 3;
    public static final int AREA = 4;
    public static final int AREA_AND_SHAPES = 5;
    
    /**
     * Creates a new XY area renderer
     */
    public XYAreaRenderer();
    
    /**
     * Creates a new XY area renderer with specified type
     * @param type the type of rendering
     */
    public XYAreaRenderer(int type);
    
    public int getPlotArea();
    public void setPlotArea(int plotArea);
    public boolean getOutline();
    public void setOutline(boolean show);
}

/**
 * Bar renderer for XY plots
 */
public class XYBarRenderer extends AbstractXYItemRenderer {
    /**
     * Creates a new XY bar renderer
     */
    public XYBarRenderer();
    
    /**
     * Creates a new XY bar renderer with margin
     * @param margin the margin around each bar
     */
    public XYBarRenderer(double margin);
    
    public double getBase();
    public void setBase(double base);
    public boolean getUseYInterval();
    public void setUseYInterval(boolean use);
    public double getMargin();
    public void setMargin(double margin);
    public boolean getDrawBarOutline();
    public void setDrawBarOutline(boolean draw);
    public GradientPaintTransformer getGradientPaintTransformer();
    public void setGradientPaintTransformer(GradientPaintTransformer transformer);
}

/**
 * Bubble chart renderer for displaying 3D data
 */
public class XYBubbleRenderer extends AbstractXYItemRenderer {
    public static final int SCALE_ON_BOTH_AXES = 0;
    public static final int SCALE_ON_DOMAIN_AXIS = 1;
    public static final int SCALE_ON_RANGE_AXIS = 2;
    
    /**
     * Creates a new bubble renderer
     */
    public XYBubbleRenderer();
    
    /**
     * Creates a new bubble renderer with scaling type
     * @param scaleType the type of scaling for bubble sizes
     */
    public XYBubbleRenderer(int scaleType);
    
    public int getScaleType();
    public void setScaleType(int scale);
}

Usage Example:

import org.jfree.chart.renderer.xy.*;
import java.awt.*;

// Customize XY line renderer
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

// Configure line appearance
renderer.setSeriesPaint(0, Color.BLUE);
renderer.setSeriesStroke(0, new BasicStroke(2.0f));
renderer.setSeriesLinesVisible(0, true);
renderer.setSeriesShapesVisible(0, true);

// Configure shapes
renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
renderer.setSeriesShapesFilled(0, true);

// Set renderer
plot.setRenderer(renderer);

// Configure bubble chart
XYBubbleRenderer bubbleRenderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_BOTH_AXES);
bubbleRenderer.setSeriesPaint(0, new Color(255, 0, 0, 128)); // Semi-transparent red
plot.setRenderer(bubbleRenderer);

Advanced Rendering Features

Advanced renderer customization including gradient fills, custom shapes, and performance optimizations.

// Gradient paint support
public interface GradientPaintTransformer {
    public GradientPaint transform(GradientPaint paint, Shape target);
}

public class StandardGradientPaintTransformer implements GradientPaintTransformer {
    public static final GradientPaintTransformType VERTICAL = new GradientPaintTransformType("VERTICAL");
    public static final GradientPaintTransformType HORIZONTAL = new GradientPaintTransformType("HORIZONTAL");
    public static final GradientPaintTransformType CENTER_VERTICAL = new GradientPaintTransformType("CENTER_VERTICAL");
    public static final GradientPaintTransformType CENTER_HORIZONTAL = new GradientPaintTransformType("CENTER_HORIZONTAL");
    
    public StandardGradientPaintTransformer();
    public StandardGradientPaintTransformer(GradientPaintTransformType type);
    public GradientPaintTransformType getType();
    public void setType(GradientPaintTransformType type);
}

// High-performance renderers for large datasets
public class SamplingXYLineRenderer extends AbstractXYItemRenderer {
    /**
     * Creates a sampling renderer for large datasets
     */
    public SamplingXYLineRenderer();
    
    public int getSeriesPixelBounding(int series);
    public void setSeriesPixelBounding(int series, int bound);
    public int getDefaultPixelBounding();
    public void setDefaultPixelBounding(int bound);
}

public class FastScatterPlot extends Plot implements ValueAxisPlot, Pannable, Zoomable {
    /**
     * Creates a fast scatter plot for large datasets
     * @param data the data array [x[], y[]] 
     * @param domainAxis the domain axis
     * @param rangeAxis the range axis
     */
    public FastScatterPlot(float[][] data, ValueAxis domainAxis, ValueAxis rangeAxis);
    
    public float[][] getData();
    public void setData(float[][] data);
    public Paint getPaint();
    public void setPaint(Paint paint);
    public boolean getDomainGridlinesVisible();
    public void setDomainGridlinesVisible(boolean visible);
    public boolean getRangeGridlinesVisible();
    public void setRangeGridlinesVisible(boolean visible);
}

// Custom shape creation utilities
public class ShapeUtilities {
    public static Shape createDiamond(float s);
    public static Shape createUpTriangle(float s);
    public static Shape createDownTriangle(float s);
    public static Shape createRegularCross(float l, float t);
    public static Shape createDiagonalCross(float l, float t);
    public static Shape createLineRegion(Line2D line, float width);
    public static Rectangle2D createTranslatedRectangle2D(Rectangle2D rectangle, double transX, double transY);
}

// Drawing supplier for consistent appearance
public interface DrawingSupplier {
    public Paint getNextPaint();
    public Paint getNextOutlinePaint();
    public Paint getNextFillPaint();
    public Stroke getNextStroke();
    public Stroke getNextOutlineStroke();
    public Shape getNextShape();
}

public class DefaultDrawingSupplier implements DrawingSupplier {
    public DefaultDrawingSupplier();
    public DefaultDrawingSupplier(Paint[] paintSequence, Paint[] fillPaintSequence, Paint[] outlinePaintSequence, Stroke[] strokeSequence, Stroke[] outlineStrokeSequence, Shape[] shapeSequence);
    
    public Paint[] getPaintSequence();
    public void setPaintSequence(Paint[] sequence);
    public Paint[] getFillPaintSequence();
    public void setFillPaintSequence(Paint[] sequence);
    public Shape[] getShapeSequence();
    public void setShapeSequence(Shape[] sequence);
}

Usage Example:

import org.jfree.chart.plot.DefaultDrawingSupplier;
import java.awt.*;

// Create custom drawing supplier
Paint[] colors = {Color.RED, Color.BLUE, Color.GREEN, Color.ORANGE};
Shape[] shapes = {
    new Rectangle2D.Double(-3, -3, 6, 6),
    new Ellipse2D.Double(-3, -3, 6, 6),
    ShapeUtilities.createDiamond(4.0f),
    ShapeUtilities.createUpTriangle(4.0f)
};

DefaultDrawingSupplier supplier = new DefaultDrawingSupplier(
    colors, colors, colors, 
    DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
    DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
    shapes);

// Apply to plot
plot.setDrawingSupplier(supplier);

// Configure gradient fills
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setSeriesPaint(0, new GradientPaint(0, 0, Color.LIGHT_BLUE, 0, 100, Color.BLUE));
renderer.setGradientPaintTransformer(new StandardGradientPaintTransformer(
    StandardGradientPaintTransformer.VERTICAL));

// High-performance rendering for large datasets
SamplingXYLineRenderer samplingRenderer = new SamplingXYLineRenderer();
samplingRenderer.setDefaultPixelBounding(2); // Sample every 2 pixels
xyPlot.setRenderer(samplingRenderer);

Install with Tessl CLI

npx tessl i tessl/maven-org-jfree--jfreechart

docs

axes-scales.md

chart-creation.md

data-management.md

export-display.md

index.md

labels-tooltips-legends.md

plots-customization.md

rendering-styling.md

tile.json