Class ModelBuilder
java.lang.Object
com.arbergashi.charts.api.ModelBuilder
ModelBuilder - Fluent API for Chart Data
End-user friendly builder for creating chart models with type-safe, self-documenting methods. Follows the builder pattern for maximum clarity.
Usage Examples:
Simple Line Chart:
ChartModel model = ModelBuilder.series("Temperature")
.addXY(0, 20.5)
.addXY(1, 21.2)
.addXY(2, 19.8)
.build();
Candlestick Chart:
ChartModel model = ModelBuilder.series("AAPL")
.color(Color.BLUE)
.addOHLC(0, 100, 105, 98, 103)
.addOHLC(1, 103, 108, 102, 106)
.addOHLC(2, 106, 107, 104, 105)
.build();
Error Bar Chart:
ChartModel model = ModelBuilder.series("Measurements")
.addWithError(0, 100, 5) // symmetric error
.addWithError(1, 105, 98, 110) // asymmetric error
.build();
From Arrays:
double[] x = {0, 1, 2, 3, 4};
double[] y = {10, 15, 13, 17, 20};
ChartModel model = ModelBuilder.series("Data")
.addXYArrays(x, y)
.build();
- Since:
- 2026-01-16
- Version:
- 1.0.0
- Author:
- Arber Gashi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBatch builder for financial data with fluent OHLC entry.static final classBatch builder for statistical data with error bars. -
Method Summary
Modifier and TypeMethodDescriptionaddAll(List<ChartPoint> points) Add multiple chart points in bulk.addOHLC(double time, double open, double high, double low, double close) Add OHLC bar (for candlestick charts).Add OHLC bar from domain object.addWithError(double x, double y, double error) Add point with symmetric error bars.addWithError(double x, double y, double errorLow, double errorHigh) Add point with asymmetric error bars.addWithError(ErrorBarPoint point) Add point with error bars from domain object.addXY(double x, double y) Add simple XY point.Add XY point with label.addXYArrays(double[] x, double[] y) Add XY data from parallel arrays.build()Build and return the chart model.Set the series color.static ModelBuilderStart building a new chart model.Set the series subtitle.
-
Method Details
-
series
Start building a new chart model.- Parameters:
name- Series name- Returns:
- new ModelBuilder instance
-
color
Set the series color.- Parameters:
color- Series color- Returns:
- this builder
-
subtitle
Set the series subtitle.- Parameters:
subtitle- Series subtitle- Returns:
- this builder
-
addXY
Add simple XY point.- Parameters:
x- X-axis valuey- Y-axis value- Returns:
- this builder
-
addXY
Add XY point with label.- Parameters:
x- X-axis valuey- Y-axis valuelabel- Point label- Returns:
- this builder
-
addOHLC
Add OHLC bar (for candlestick charts).- Parameters:
time- X-axis value (timestamp or index)open- Opening pricehigh- Highest pricelow- Lowest priceclose- Closing price- Returns:
- this builder
-
addOHLC
Add OHLC bar from domain object.- Parameters:
bar- OHLC data bar- Returns:
- this builder
-
addWithError
Add point with symmetric error bars.- Parameters:
x- X-axis valuey- Y-axis value (mean)error- Symmetric error margin (±)- Returns:
- this builder
-
addWithError
Add point with asymmetric error bars.- Parameters:
x- X-axis valuey- Y-axis value (mean)errorLow- Lower bounderrorHigh- Upper bound- Returns:
- this builder
-
addWithError
Add point with error bars from domain object.- Parameters:
point- Error bar data point- Returns:
- this builder
-
addAll
Add multiple chart points in bulk.- Parameters:
points- List of chart points- Returns:
- this builder
-
addXYArrays
Add XY data from parallel arrays.- Parameters:
x- Array of X valuesy- Array of Y values- Returns:
- this builder
-
build
Build and return the chart model.- Returns:
- configured DefaultChartModel
-