XChart Java plotting library: setup, chart types, and export
XChart is a light-weight Java library for plotting data.
At a glance
- What is it?
- XChart is a lightweight Java library for creating charts from arrays, styling them, embedding them in Swing, and exporting them to raster or vector files. It is most practical for Java desktop applications and data visualizations that need direct chart APIs without required plotting dependencies.
- Who is it for?
- XChart fits Java developers who want direct chart construction, Swing integration, and file export from application code. It does not fit projects requiring undocumented dependency coordinates, a server-side rendering workflow, or a complete production design system.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 4 days ago.
- What is it written in?
- Mainly Java, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.
Editorial analysis
XChart's Java data-to-chart API
XChart solves the problem of turning numeric or categorical data into a chart without requiring a separate plotting application or a mandatory third-party plotting dependency. Its intended audience is Java developers building desktop interfaces, reports, monitoring views, or tools that need charts generated directly by application code.
The library supports line, step, scatter, area, bar, histogram, pie, donut, bubble, radar, OHLC, box, heat-map, dial, and related chart forms. It also documents multiple Y axes, grouped Y axes, logarithmic axes, several X-axis data types, multiple series, tool tips, error bars, themes, legends, and point-level listeners. That range is broad for a library described as lightweight, but the feature list does not explain whether every chart type has the same customization depth.
XChart offers two visible entry points. `QuickChart` minimizes setup for a basic chart. `XYChartBuilder` exposes chart dimensions, titles, styling, and series configuration. The second approach is the better fit when the chart needs a deliberate appearance or interactive behavior. For applications that already have chart-producing code, XChart is primarily a rendering and interaction layer rather than a data-processing framework.
How XChart constructs and updates charts
The chart object receives X and Y data through constructors or builder calls, then holds a configured series model. In the simplest documented path, `QuickChart.getChart` receives a title, axis titles, a series name, and parallel `double[]` values. The resulting `XYChart` can be displayed through `SwingWrapper` or passed to an encoder.
The styling API is attached to the chart through `getStyler()`. The README shows controls for render style, title visibility, legend position, and marker size. Series objects can also be retained after being added, allowing calls such as `setMarker`. This separation matters for applications that need repeatable styling rules rather than a single hard-coded example.
For live views, the documented update path calls `updateXYSeries` on the chart and then calls `revalidate()` and `repaint()` on `XChartPanel`. That mechanism updates the series and asks the Swing component to refresh. The README does not describe buffering, animation, thread safety, rate limits, or update performance, so it does not support assumptions about high-frequency financial or telemetry workloads.
For desktop embedding, `XChartPanel<XYChart>` is placed inside a normal `JFrame`. GUI creation is scheduled through `SwingUtilities.invokeLater`, which keeps window construction on the event-dispatching thread as required by Swing.
Creating a first XChart chart in Java
The README does not provide installation commands, Maven coordinates, Gradle configuration, or a version-specific dependency block. It points readers to the project homepage at `http://knowm.org/open-source/xchart` and shows the Java API, but the documentation does not provide a verified build dependency. A reader must first resolve the library through the project's documented distribution channel and add the appropriate module to the application build.
Once XChart is on the Java classpath, this complete example creates a chart from two arrays, displays it, and writes a PNG file:
double[] xData = new double[]{0.0, 1.0, 2.0};
double[] yData = new double[]{2.0, 1.0, 0.0};
XYChart chart = QuickChart.getChart("Sample Chart", "X", "Y", "y(x)", xData, yData);
new SwingWrapper(chart).displayChart();
ChartEncoder.saveChart(chart, "./Sample_Chart", "png");`displayChart()` opens the chart through the README's Swing wrapper. `saveChart` writes a raster image using the requested filename and format. The first real result should be a three-point `XYChart` corresponding to the supplied arrays, with the file written relative to the process working directory.
The README also shows a 300 DPI bitmap export:
BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.PNG, 300);Use this call when a bitmap needs a declared DPI value. The README does not specify the exact image dimensions produced by that setting, so it should not be treated as a guarantee of a particular pixel size.
XChart styling and Swing embedding controls
For a chart with explicit dimensions and custom appearance, `XYChartBuilder` exposes width, height, title, and axis titles. The chart styler can select scatter rendering, hide the chart title, move the legend inside the southwest corner, and increase the marker size. Each series can then receive its own marker.
The relevant construction pattern is:
XYChart chart = new XYChartBuilder()
.width(600).height(500)
.title("Gaussian Blobs")
.xAxisTitle("X").yAxisTitle("Y")
.build();
chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter);
chart.getStyler().setChartTitleVisible(false);
chart.getStyler().setLegendPosition(LegendPosition.InsideSW);
chart.getStyler().setMarkerSize(16);This API is explicit enough to centralize chart configuration in application code. It also exposes a design choice: hiding the title while retaining axis titles is possible, but the README does not explain accessibility behavior for a chart whose visual title is suppressed.
For a Swing application, the chart is added to a `JFrame` through `XChartPanel`. The documented advanced example also adds a label beneath the chart and uses `pack()` and `setVisible(true)` to display the window. That makes XChart suitable for a conventional desktop layout rather than requiring a separate chart-hosting framework.
The feature list includes tool tips and data-point listeners for hover, exit, and click events on bars, markers, and slices. It also documents right-click Save-As behavior. However, it does not specify keyboard navigation, screen-reader labels, selection state, or event ordering. Those details would need verification for an application with accessibility requirements.
XChart export formats and optional dependencies
XChart separates raster and vector export. `ChartEncoder.saveChart` selects an encoder from a format string. The documented raster path uses `javax.imageio.ImageIO`, so formats supported by the current JDK classpath can be written without an additional XChart-specific encoder.
The README gives these unified calls:
ChartEncoder.saveChart(chart, "./MyChart", "png");
ChartEncoder.saveChart(chart, "./MyChart", "tiff");
ChartEncoder.saveChart(chart, "./MyChart", "svg");
ChartEncoder.saveChart(chart, "./MyChart", "pdf");
byte[] bytes = ChartEncoder.getBytes(chart, "png");PNG, JPG, BMP, GIF, and TIFF are listed as raster formats. Other raster formats can work when a matching `ImageIO` writer is present on the classpath. The README names `com.github.usefulness:webp-imageio` as an example dependency for WebP. It also describes an AVIF fallback that pipes PNG data through the `avifenc` command-line tool, including a `brew install libavif` example for one environment.
SVG, EPS, and PDF require optional dependencies. The README excerpt names the general optional libraries `de.erichseifert.vectorgraphics2d` and `pdfbox-graphics2d`, but it cuts off the dependency table before showing full build entries. Those optional encoders are marked `<optional>true</optional>`, so they are not pulled transitively. Applications must add the specific encoder dependency they need. This is a real adoption constraint: PNG is the lowest-friction export path, while vector and PDF output require checking the complete dependency instructions.
The chart can also be resized before export:
chart.setSize(1920, 1080);
ChartEncoder.saveChart(chart, "./MyChart", "png");That call changes the chart size before encoding. The README does not describe resampling behavior for bitmap output or whether all chart components recalculate identically at the new dimensions.
XChart limitations, licensing, and maintenance
XChart's main limitation is not chart variety but the amount of implementation detail in the README. The README is strong on API entry points, chart types, styling, Swing embedding, and export, but it does not document dependency installation, release artifacts, semantic versioning guarantees, or performance behavior. The repository has no GitHub releases, so consumers cannot rely on a release list there.
It is also a Java library centered on chart objects and Swing-oriented presentation. The README does not describe a web renderer, HTML canvas, browser deployment, headless web component, or remote rendering service. XChart would therefore be the wrong tool if the target is a browser chart delivered without a Java runtime, unless another component converts the output into an image.
The repository is not archived, and its last push was on 2026-10-08. That supports describing the repository as recently changed, but the absence of GitHub releases means upgrade planning still requires checking the repository history and build metadata. The repository includes a Maven `pom.xml`, a core `xchart/` directory, demos, and a site, but the README does not state release cadence or a supported upgrade path.
The repository is licensed under Apache-2.0. That identifier indicates the license selected by the project, but this review does not interpret legal obligations or provide legal advice. Applications should review the repository `LICENSE` and `NOTICE` files alongside their own distribution requirements.
Editorial conclusion
XChart fits Java developers who want direct chart construction, Swing integration, and file export from application code. It does not fit projects requiring undocumented dependency coordinates, a server-side rendering workflow, or a complete production design system. Verify the available Maven artifact for your chosen release, Java compatibility, chart interaction requirements, and output format dependencies before adopting it.
Frequently asked questions
What is XChart used for in Java?
XChart is a lightweight Java library for turning data into charts, displaying them through Swing wrappers or panels, and exporting them to files. The README documents support for line, scatter, bar, area, pie, histogram, heat-map, and other chart types.
How do I create an XChart chart from arrays?
Use `QuickChart.getChart` with a title, axis titles, series name, X data, and Y data. The README example then calls `new SwingWrapper(chart).displayChart()` to show it or `ChartEncoder.saveChart` to save it.
Does XChart support PNG and PDF export?
The README documents PNG and other raster formats through `ChartEncoder`. SVG, EPS, and PDF export require optional dependencies, and the README excerpt does not include the complete dependency table.
Can XChart update a chart in real time?
The README says to call `updateXYSeries` on the `XYChart`, followed by `revalidate()` and `repaint()` on an `XChartPanel`. It does not document performance limits, buffering, or thread-safety guarantees for rapid updates.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/knowm-xchart)Was this useful?