JFreeChart Documentation

repository·master·Indexed 23 days ago

https://github.com/jfree/jfreechart

A comprehensive, free chart library for the Java platform supporting client-side usage (Swing and JavaFX) and server-side usage. It provides export capabilities to SVG, PNG, and PDF formats. The library includes features such as chart theming, heat maps via HeatMapDataset, and interactive ChartPanel buffering and zooming. Requires JDK 11 or later (with Java 8 support available via the v1.5.x branch).

Tokens
1.9K
Snippets
2
Records
19
Agent score
30%

What's inside JFreeChart

  1. Use experimental classes in org.jfree.experimental

    master

    JFreeChart includes an org.jfree.experimental.* namespace containing incomplete classes. These are provided for developers to test and provide feedback.

    Warning: The API for these classes is subject to change and they are not part of the standard stable API.

  2. Use the Chart theming mechanism

    master

    Version 1.0.11 introduced a chart theming mechanism to allow charts to be restyled conveniently.

    Key components include:

    • ChartTheme: A new interface for defining themes.
    • StandardChartTheme: A new class providing a standard theme.
    • ChartFactory: Provides getChartTheme() and setChartTheme() methods.
    • ChartUtilities: Provides applyCurrentTheme() to apply a theme to a chart.
  3. Use SlidingCategoryDataset and SlidingGanttDataset for scrolling charts

    master
    The SlidingCategoryDataset and SlidingGanttDataset classes allow you to plot a subset of categories. This enables charts to simulate a scrolling effect by moving through the dataset.
  4. Review JFreeChart API changes and breaking adjustments

    master

    When upgrading JFreeChart, be aware of several historical API adjustments that may affect your code. While many versions focused on adding methods without removing or deprecating existing ones, some specific changes occurred:

    • XYItemRenderer and CategoryItemRenderer: Numerous series override settings were deprecated in version 1.0.6.
    • CategoryItemEntity: In version 1.0.6, row and column index attributes were replaced with row and column key attributes.
    • DatasetUtilities.sampleFunction2D(): In a recent update, this method was changed to sample the correct number of points. You should audit any code calling this method to ensure compatibility with the new sampling logic.
    • StandardXYItemRenderer: An override field was deprecated in version 1.0.8.

    Always check the specific version release notes for the API Adjustments section to identify new methods available for your use cases.

  5. Install JFreeChart via Maven

    master

    To use JFreeChart in your Java projects, add the following dependency to your build tool (e.g., pom.xml for Maven):

    <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.5.6</version>
        </dependency>

    Requirements:

    • JDK 11 or later.
    • For Java 8 support, use the v1.5.x branch.
    <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.5.6</version>
        </dependency>
  6. Migrate from JFreeChart 1.0.x to 1.5.0

    master

    When migrating from JFreeChart 1.0.x to JFreeChart 1.5.0, be aware of the following breaking API changes:

    • JCommon Integration: All JCommon classes used by JFreeChart are now integrated within the JFreeChart JAR in a different package. You must update your imports.
    • Method Renaming: Many methods following the getBaseXXX()/setBaseXXX() pattern have been renamed to getDefaultXXX()/getDefaultXXX().
    • Class Renaming:
      • ChartUtilities is now ChartUtils.
      • org.jfree.chart.utils.ParamChecks is now org.jfree.chart.utils.Args.
    • Removed Classes:
      • Pseudo-3D chart classes have been removed (use Orson Charts for better 3D charts).
      • SegmentedTimeline has been removed.

    For more details, refer to Issue 66.

  7. Build the JavaScript utilities for JFreeSVG

    master

    The JavaScript utility code in this directory is used when exporting charts to SVG format with JFreeSVG. To build the library, use the build.sh script.

    Requirement: You must have the Google Closure Compiler jar file available on your classpath. You will need to edit the build.sh script to point to the correct location of your local Google Closure Compiler jar.

  8. Configure ChartPanel buffering and zoom behavior

    master

    The ChartPanel class provides several interactive features. In version 1.0.13, a useBuffer flag was introduced to improve performance and address JRE drawing regressions.

    • When useBuffer is true (the default), charts are rendered into an off-screen image before being displayed. This improves performance but increases memory usage per ChartPanel.
    • When useBuffer is false, the zoom rectangle is drawn using XOR mode.

    ChartPanel also supports:

    • Copying charts to the clipboard.
    • Panning.
    • Mouse-wheel zooming.
  9. Create Heat Map charts with HeatMapDataset

    master

    Version 1.0.13 added support for heat maps. To create a heat map chart, use the following components:

    • HeatMapDataset: The interface for heat map data.
    • DefaultHeatMapDataset: The standard implementation of the interface.
    • HeatMapUtilities: A utility class to assist in creating heat map charts.
  10. Use new XYPlot and CategoryPlot marker management methods

    master
    In recent versions, XYPlot and CategoryPlot have added methods to manage markers, including addMarker() and removeDomainMarker() / removeRangeMarker(). These methods support optional notification of listeners.