The Chart Java API (patternfly-java-charts module) provides Java component wrappers for PatternFly chart visualizations. This module packages chart components as a GWT library (gwt-lib) that integrates with both GWT and J2CL applications. The Java API serves as a type-safe interface to chart web components that are implemented using React and distributed via the @patternfly-java/charts NPM package.
For information about the underlying web component implementation, see Chart Web Components. For details on the NPM package build process, see Chart Build and Publishing.
The patternfly-java-charts module follows the standard PatternFly Java architecture but uses specialized packaging to support chart-specific requirements. The module provides Java component classes that extend BaseComponent and integrate with the chart web components at runtime.
Sources: charts/pom.xml1-77
The charts module uses the gwt-lib packaging type, which differs from standard JAR packaging in several important ways:
| Aspect | Configuration | Purpose |
|---|---|---|
| Packaging Type | gwt-lib | Produces a GWT library archive suitable for both GWT and J2CL consumption |
| Module Name | org.patternfly.Charts | Defines the GWT module descriptor location |
| Resource Inclusion | .js files from src/main/java and src/main/resources | Includes JavaScript resources needed by chart components |
The gwt-lib packaging is configured via the gwt-maven-plugin:
This packaging type ensures that:
.gwt.xml files) are preservedSources: charts/pom.xml31 charts/pom.xml68-74
The charts module depends on two core PatternFly Java modules:
patternfly-java-core - Provides foundational classes:
BaseComponent for HTML element wrappingpatternfly-java-tokens - Provides design system integration:
Token enum with CSS custom propertiesSources: charts/pom.xml35-43
The charts module includes JavaScript files as resources, which are packaged with the GWT library for runtime access. This configuration allows chart components to load necessary JavaScript code when integrated into applications.
The resource configuration includes two directories:
This dual-directory approach allows:
src/main/java)src/main/resources)Sources: charts/pom.xml52-64
The module defines a GWT module descriptor named org.patternfly.Charts, which serves as the entry point for integrating chart components into GWT applications. Applications using charts must inherit this module in their own .gwt.xml file:
The module descriptor:
patternfly-java-core and patternfly-java-tokens modulesSources: charts/pom.xml72
Chart components in the Java API follow the standard PatternFly Java component pattern, extending BaseComponent to wrap custom HTML elements. The architecture bridges type-safe Java code with React-based web components through a carefully designed interop layer:
Chart Component Flow
ChartDonut)<pfj-chart-donut>)ReactWrapperElement renders corresponding React chart componentSources: charts/pom.xml36-39 charts/src/main/resources/META-INF/externs/charts.externs.js1-205
The Java API provides components for the following chart types:
| Chart Type | Java Component | Web Component Tag | React Component |
|---|---|---|---|
| Donut Chart | ChartDonut | pfj-chart-donut | ChartDonut |
| Donut Utilization | ChartDonutUtilization | pfj-chart-donut-utilization | ChartDonutUtilization |
| Donut Threshold | ChartDonutThreshold | pfj-chart-donut-threshold | ChartDonutThreshold |
| Bullet Chart | ChartBullet | pfj-chart-bullet | ChartBullet |
| Pie Chart | ChartPie | pfj-chart-pie | ChartPie |
Each Java component extends BaseComponent and provides builder methods for chart configuration.
Sources: charts/npm/README.md9-15 charts/npm/demo.html49-109
For J2CL compilation, the charts module includes a Closure Compiler externs file that declares JavaScript types used by chart components. This ensures property names are preserved during minification and provides type checking between Java and JavaScript.
Externs File Structure
Title: Externs Type Hierarchy
Key Extern Declarations
The externs file declares constructors and properties for:
Base Chart Properties (declared on ChartElement):
categories - Array of category stringsheight / width - Numeric dimensionslabels - Function for label generation (LabelsFn)legendData - Array of legend entrieslegendOrientation / legendPosition - String constantspadding - Padding object with top/right/bottom/leftsubTitle / title - Title stringsthemeColor - Theme color stringDonut-Specific Properties (declared on DonutElement, DonutUtilizationElement, DonutThresholdElement):
data - Chart data array or single data pointthresholds - Array of threshold values for utilization chartsBullet-Specific Properties (declared on BulletElement):
comparativeErrorMeasureData / comparativeWarningMeasureData - Comparative measure arraysprimaryDotMeasureData / primarySegmentedMeasureData - Primary measure arraysqualitativeRangeData - Range data array*LegendData arrays for each measure typeWhy Externs Are Necessary
When J2CL compiles Java to JavaScript, the Closure Compiler performs aggressive optimizations including property renaming. Without externs:
data, height, labels would be minifiedThe externs file tells Closure Compiler: "These property names are part of an external API - preserve them exactly as written."
Sources: charts/src/main/resources/META-INF/externs/charts.externs.js1-205
Java components use a fluent builder API consistent with other PatternFly Java components. Chart data is typically set via properties that correspond to the web component attributes:
Chart components accept data in formats that match the web component API:
Simple Data (for donut utilization):
Array Data (for donut, pie, bullet charts):
Threshold Data (for utilization with thresholds):
Charts can be updated after creation by modifying properties:
Charts support legend customization through properties:
Bullet charts have specialized data properties for different measure types:
Sources: charts/npm/demo.html54-109 charts/npm/README.md33-85 charts/npm/src/components/pfj-chart-bullet.js19-193
The Java API properties map to web component attributes and JavaScript properties. The mapping follows these patterns:
Attribute Conversion:
legendPosition → legend-positionProperty Types:
Parsing in Web Components:
The web component layer (ReactWrapperElement) parses attributes using parseAttrValue:
The BOM (patternfly-java-bom) manages the version automatically.
Inherit the Charts module in your .gwt.xml file:
This:
For J2CL projects:
patternfly-java-charts in the classpathpatternfly-java-j2cl module is present (handles integration)META-INF/externs/ directoryThe J2CL build process:
NPM Package Installation
The @patternfly-java/charts NPM package must be available at runtime:
JavaScript Import
Import the chart components in your application's main JavaScript file:
This registers the custom element definitions for all chart web components.
PatternFly CSS
Charts require PatternFly stylesheets:
Complete Example (from showcase application):
Sources: charts/pom.xml1-77 showcase/src/web/main.js16-19 showcase/package.json21-25
When compiling chart components with J2CL:
Externs Location
The externs file is located at:
charts/src/main/resources/META-INF/externs/charts.externs.js
J2CL automatically discovers and applies externs from META-INF/externs/ directories in dependencies.
Resource Packaging
The build configuration ensures JavaScript resources are packaged:
This configuration:
.js files from src/main/java (co-located with Java sources).js files from src/main/resources (standalone resources)JsInterop Annotations
While the externs file provides type declarations, Java chart components may use @JsType, @JsProperty, and related annotations for direct JavaScript interop. These annotations:
Sources: charts/pom.xml52-64 charts/src/main/resources/META-INF/externs/charts.externs.js1-25
The charts module includes JUnit Jupiter for unit testing, following the standard PatternFly Java testing approach:
Tests verify:
Sources: charts/pom.xml45-48
Refresh this wiki