Line2D
Line2D widget draws a line chart: one value per category on the X axis, a number on the Y axis.
Several lines are shown when the records are grouped by a field. The user can switch the chart to a table.
Basics
How does it look?

Every record of the business component is one point of the chart. The widget takes the point from two fields:
xValueFieldKey: the field with the category on the X axis (a month, a client, a date as text).yValueFieldKey: the numeric field with the value on the Y axis.
The title of these fields is shown as the axis title. Records without a Y value are skipped.
The backend returns the records in the order of the X axis: the chart does not sort them.
Options of options.chart2D:
| Option | Required | Description |
|---|---|---|
xValueFieldKey |
yes | Field key for the X axis. |
yValueFieldKey |
yes | Field key for the Y axis. Must be a numeric field type (number, money, percent). |
groupFieldKey |
no | Field key that splits the records into lines. One line per value, the values are shown in the legend. See Groups. |
stack |
no | true draws the lines one on top of the other. See Stack. |
yMin, yMax, yStep |
no | Scale and step of the Y axis. See Axis scale and step. |
xMin, xMax, xStep |
no | Scale and step of the X axis. Only for a numeric X field. See Axis scale and step. |
descriptionFieldKey |
no | Field keys shown in the tooltip instead of the X value. See Tooltip. |
How to add?
Example
Step1 Create DataResponseDTO with the fields of a point: the X value and the Y value.
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class MyExampleDTO extends DataResponseDTO {
private String month;
private Long sum;
}
Step2 Create DAO extends AbstractAnySourceBaseDAO<> implements AnySourceBaseDAO.
The DAO returns one record per point, sorted along the X axis, with a unique id.
@NonNull
private List<MyExampleDTO> getStats() {
return repository.findAll().stream()
.collect(Collectors.groupingBy(MyEntity::getMonth, Collectors.summingLong(MyEntity::getSum)))
.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(e -> {
MyExampleDTO dto = new MyExampleDTO()
.setMonth(monthName(e.getKey()))
.setSum(e.getValue());
dto.setId(e.getKey().toString());
return dto;
}).toList();
}
Step3 Create Meta extends AnySourceFieldMetaBuilder.
@SuppressWarnings("EmptyMethod")
@Service
public class MyExampleMeta extends AnySourceFieldMetaBuilder<MyExampleDTO> {
@Override
public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, BcDescription bc,
String id, String parentId) {
}
@Override
public void buildIndependentMeta(FieldsMeta<MyExampleDTO> fields, BcDescription bc, String parentId) {
}
}
Step4 Create Service extends AnySourceVersionAwareResponseService.
@SuppressWarnings({"java:S", "java:S"})
@RequiredArgsConstructor
@Service
public class MyExampleService extends AnySourceVersionAwareResponseService<MyExampleDTO, MyExampleDTO> {
@Getter(onMethod_ = @Override)
private final Class<MyExampleMeta> meta = MyExampleMeta.class;
@Getter(onMethod_ = @Override)
private final Class<MyExampleDao> dao = MyExampleDao.class;
@Override
protected CreateResult<MyExampleDTO> doCreateEntity(MyExampleDTO entity, BusinessComponent bc) {
return new CreateResult<>(entityToDto(bc, entity));
}
@Override
protected ActionResultDTO<MyExampleDTO> doUpdateEntity(MyExampleDTO entity, MyExampleDTO data, BusinessComponent bc) {
return new ActionResultDTO<>(entityToDto(bc, entity));
}
}
Step5 Create file .widget.json with type = "Line2D".
Add the fields of the point and options.chart2D with xValueFieldKey and yValueFieldKey.
{
"name": "myexamplelined",
"title": "Sales sum per month",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum"
}
}
}
Step6 Add widget to corresponding .view.json.
{
"name": "myexamplelined",
"title": "LineD",
"url": "/screen/myexample/view/myexamplelined",
"template": "DashboardView",
"widgets": [
{
"widgetName": "secondlevelmenu",
"position": 0,
"gridWidth": 24
},
{
"widgetName": "myexamplelined",
"position": 20,
"gridWidth": 24
}
],
"rolesAllowed": [
"CXBOX_USER"
]
}
Step7 Set the page limit of the business component to the number of points, for example 1000. The default limit is 5. When the business component has more records than the limit, the widget shows only the table. See Page limit.
Add the business component to the BC_PROPERTIES table:
Title
Title Basic
Title for widget (optional)
There are types of:
constant title: shows constant text.constant title empty: if you want to visually connect widgets by them to be placed one under another
How does it look?


How to add?
Example
Step1 Add name for title to .widget.json.
{
"name": "myexamplelined",
"title": "Sales sum per month",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum"
}
}
}
Step1 Add empty title to .widget.json.
Title Color
not applicable
Business component
This specifies the business component (BC) to which this widget belongs. A business component represents a specific part of a system that handles a particular business logic or data.
The chart takes the data from an AnySource business component: the DAO builds the points (for example, a sum per month)
and returns them in the order of the X axis. One record is one point, so the id of a record must be unique.
see more Business component
Show condition
no show condition - recommended: widget always visibleshow condition by current entity: the chart is shown when a field of the current record of another business component on the view has the given value
Tips
It is recommended not to use Show condition when possible, because wide usage of this feature makes application hard to support.
How does it look?


How to add?
Example
see Basic
Step1 Add showCondition to .widget.json. see more showCondition
{
"name": "myexamplelined",
"title": "Sales sum per month",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum"
}
},
"showCondition": {
"bcName": "myExampleBcForm",
"params": {
"fieldKey": "customFieldShowCond",
"value": "true"
}
}
}
Fields
Fields Configuration. The fields array defines the fields of a point. The chart uses the fields named in options.chart2D;
the other fields are shown in the table mode and in the tooltip.
- "title"
Description: Field Title. For the X and Y fields it is the axis title. An empty title hides the axis title.
Type: String(optional).
-
"key"
Description: Name field to corresponding DataResponseDTO.
Type: String(required).
-
"type"
Description: Field types. The Y field must be numeric.
Type: String(required).
A field with type hidden is not shown in the table mode. Use it for the values that only the drilldown filter needs.
How to add?
Example
Add field to .widget.json.
{
"name": "myexamplelined",
"title": "Sales sum per month",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum"
}
}
}
Options layout
options.layout - no use in this type.
Actions
not applicable
Additional properties
Tooltip
The tooltip appears when the user moves the mouse over a point. By default it shows the X value and the value of every line.
descriptionFieldKey replaces it with the values of the listed fields of the record, joined with a comma.
How does it look?

How to add?
Example
Step1 Add the description field to fields and descriptionFieldKey to options.chart2D in .widget.json.
{
"name": "myexamplelined",
"title": "Sales sum per month and product",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
},
{
"title": "Description",
"key": "description",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum",
"groupFieldKey": "productName",
"descriptionFieldKey": [
"description"
]
}
}
}
Color
The color of the lines is set on the X field:
bgColorKey: the key of the field with the color of the record. The line takes the color of its first record.bgColor: one constant color for all lines.
Without them the widget uses the default palette.
How does it look?


How to add?
Example
Step1 Add the color field to DataResponseDTO and fill it in the DAO.
@NonNull
private List<MyExampleDTO> getStats() {
return repository.findAll().stream()
.collect(Collectors.groupingBy(s -> s.getMonth() + "-" + s.getProductName().name(),
Collectors.summingLong(MyEntity::getSum)))
.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(e -> {
String[] key = e.getKey().split("-");
ProductEnum product = ProductEnum.valueOf(key[1]);
MyExampleDTO dto = new MyExampleDTO()
.setMonth(monthName(Long.valueOf(key[0])))
.setProductName(product)
.setSum(e.getValue())
.setColor(ProductEnum.EQUIPMENT.equals(product) ? "#4DE" : "#30BAF");
dto.setId(e.getKey());
return dto;
}).toList();
}
{
"name": "myexamplelinedcolorkey",
"title": "Color from a field (bgColorKey)",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input",
"bgColorKey": "color"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum",
"groupFieldKey": "productName"
}
}
}
Step1 Add bgColor to the X field in .widget.json.
{
"name": "myexamplelinedcolor",
"title": "Constant color (bgColor)",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input",
"bgColor": "#ED"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum",
"groupFieldKey": "productName"
}
}
}
Drilldown
A click on a point opens the view with the records behind the point. The drilldown is set on the X field:
drillDown: true in the widget and the target view with a filter in the Meta of the record.
With groupFieldKey the point knows its line, so the filter can include the group value.
In the table mode the X value is a link with the same drilldown.
How does it look?

How to add?
Example
Step1 Add drillDown to the X field in .widget.json.
{
"name": "myexamplelined",
"title": "Sales sum per month and product",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input",
"drillDown": true
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
},
{
"title": "Month number",
"key": "monthNumber",
"type": "hidden"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum",
"groupFieldKey": "productName"
}
}
}
@Override
public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, BcDescription bc,
String id, String parentId) {
var month = fields.getCurrentValue(MyExampleDTO_.monthNumber).orElse(null);
var product = fields.getCurrentValue(MyExampleDTO_.productName).orElse(null);
fields.setDrilldownWithFilter(
MyExampleDTO_.month,
DrillDownType.INNER,
"/screen/myexample/view/myexamplelist",
fc -> fc
.add(PlatformMyExampleController.myExampleBcList, MyExampleListDTO.class, fb -> fb
.number(MyExampleListDTO_.month, month)
.dictionaryEnum(MyExampleListDTO_.productName, product))
);
}
@Getter
@Setter
@NoArgsConstructor
public class MyExampleListDTO extends DataResponseDTO {
@SearchParameter(name = "month", provider = LongValueProvider.class)
private Long month;
@SearchParameter(name = "clientName")
private String clientName;
@SearchParameter(name = "productName", provider = EnumValueProvider.class)
private ProductEnum productName;
@SearchParameter(name = "sum", provider = LongValueProvider.class)
private Long sum;
public MyExampleListDTO(MyEntity entity) {
this.id = entity.getId().toString();
this.month = entity.getMonth();
this.clientName = entity.getClientName();
this.productName = entity.getProductName();
this.sum = entity.getSum();
}
}
see more DrillDown
Table mode
The settings icon of the widget opens the Mode menu with Chart and Table. In the table mode the widget shows the records
as a table with a column per field of the widget (fields with type hidden are not shown).
How does it look?

How to add?
The table mode is always available, nothing to add.
Groups
groupFieldKey splits the records into lines: one line per value of the field. The values are shown in the legend.
A click on a legend value hides or shows the line.
Without groupFieldKey the chart has one line, and the legend shows the title of the Y field.
How does it look?

How to add?
Example
Step1 Add groupFieldKey to options.chart2D in .widget.json. The DAO returns one record per X value and group.
{
"name": "myexamplelined",
"title": "Sales sum per month and product",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum",
"groupFieldKey": "productName"
}
}
}
Stack
stack: true draws the lines one on top of the other: the point of a line is its value plus the values of the lines below.
Use it with groupFieldKey.
How does it look?

How to add?
Example
Step1 Add stack to options.chart2D in .widget.json.
{
"name": "myexamplelined",
"title": "Sales sum per month, stacked by product",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum",
"groupFieldKey": "productName",
"stack": true
}
}
}
Axis scale and step
yMin, yMax set the range of the Y axis, yStep sets the distance between the axis labels.
Without them the range is taken from the data.
xMin, xMax, xStep do the same for the X axis and work only when the X field has a numeric type.
For a text X field they are ignored, and the widget writes a message to the browser console.
How does it look?

How to add?
Example
Step1 Add yMin, yMax, yStep to options.chart2D in .widget.json.
{
"name": "myexamplelined",
"title": "Sales sum per month",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum",
"yMin": 0,
"yMax": 10000,
"yStep": 2000
}
}
}
DualAxes2D
A Line2D widget can be combined with a Column2D widget in one area with the DualAxes2D widget:
the charts share the X axis and can have separate Y axes.
Customization of displayed columns
not available in this release.
Filtration
Basic
Works only in the table mode: the column filters are shown for the fields with enableFilter in the Meta, as in a List widget.
In the chart mode there are no filters. The widget sends the filter to the backend, and the AnySource DAO of the chart applies it itself. After the switch back to the chart, the chart draws only the filtered records. The chart mode does not show that a filter is applied: the filter is cleared in the table mode.
see more Filtration
How to add?
Example
When the data of the chart come from an AnySource DAO, the DAO applies the filter itself.
Step 1 Add @SearchParameter to corresponding DataResponseDTO.
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class MyExampleDTO extends DataResponseDTO {
@SearchParameter(name = "month")
private String month;
private Long sum;
}
Step 2 Add fields.enableFilter to corresponding FieldMetaBuilder.
@Override
public void buildIndependentMeta(FieldsMeta<MyExampleDTO> fields, BcDescription bc, String parentId) {
fields.enableFilter(MyExampleDTO_.month);
}
Step 3 Apply the filter in getList of the AnySource DAO.
@Override
public Page<MyExampleDTO> getList(final BusinessComponent bc, final QueryParameters queryParameters) {
Stream<MyExampleDTO> stats = getStats().stream();
for (FilterParameter filter : queryParameters.getFilter()) {
if (MyExampleDTO_.month.getName().equals(filter.getName())
&& filter.getOperation() == SearchOperation.CONTAINS) {
stats = stats.filter(dto -> Strings.CI.contains(dto.getMonth(), filter.getStringValue()));
}
}
return new PageImpl<>(stats.toList());
}
FullTextSearch
Works only in the table mode with options.fullTextSearch in .widget.json: the search input is shown above the table.
The widget sends the search text to the backend, and the AnySource DAO of the chart applies it itself. After the switch back to the chart, the chart draws only the filtered records. The chart mode does not show that a filter is applied: the filter is cleared in the table mode.
see FullTextSearch
How to add?
Example
When the data of the chart come from an AnySource DAO, the DAO applies the search itself.
Step 1 Add extension file FullTextSearchExt.java
import java.util.Optional;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;
import org.cxbox.core.crudma.bc.BusinessComponent;
@UtilityClass
public class FullTextSearchExt {
@NonNull
public static Optional<String> getFullTextSearchFilterParam(BusinessComponent bc) {
return Optional.ofNullable(bc.getParameters().getParameter("_fullTextSearch"));
}
public static Predicate likeIgnoreCase(String value, CriteriaBuilder cb, Path<String> path) {
return cb.like(cb.lower(path), StringUtils.lowerCase("%" + value + "%"));
}
}
Step 2 Apply the search text in getList of the AnySource DAO.
@Override
public Page<MyExampleDTO> getList(final BusinessComponent bc, final QueryParameters queryParameters) {
Optional<String> text = FullTextSearchExt.getFullTextSearchFilterParam(bc);
return new PageImpl<>(getStats().stream()
.filter(dto -> text.map(value -> Strings.CI.contains(dto.getMonth(), value)).orElse(true))
.toList());
}
Step 3 Add fullTextSearch to corresponding .widget.json.
enabled true/false
placeholder - description for fullTextSearch
{
"name": "myexamplelined",
"title": "Sales sum per month",
"type": "LineD",
"bc": "myExampleBc",
"fields": [
{
"title": "Month",
"key": "month",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "month",
"yValueFieldKey": "sum"
},
"fullTextSearch": {
"enabled": true,
"placeholder": "Find by month"
}
}
}
Personal filter group
not available in this release: the settings menu of the chart has only the Mode items, so there is no Save filters item.
Filter group
Works only in the table mode: the filter groups of the business component are shown above the table, as in a List widget. The widget sends the filter of the chosen group to the backend, and the AnySource DAO of the chart applies it itself. After the switch back to the chart, the chart draws only the filtered records. The chart mode does not show that a filter is applied: the filter is cleared in the table mode. see Filter group
How to add?
Example
When the data of the chart come from an AnySource DAO, the DAO applies the filter of the group itself.
Tips
To get the conditions for the filters column, follow these steps:
- Add a filter function for fields
- Visually fill in the necessary filters in the interface.
- Open the developer panel.
- Locate the required request.
- Use the filter part of this request as the
filtersvalue

Step 1 Add business component in BC_FILTER_GROUPS TABLE
name;bc;filters;ID
Sum from 5000;myExampleBc4274;sum.greaterOrEqualThan=5000;
Sum under 5000;myExampleBc4274;sum.lessThan=5000;
Step 2 Apply the filter in getList of the AnySource DAO.
@Override
public Page<MyExampleDTO> getList(final BusinessComponent bc, final QueryParameters queryParameters) {
Stream<MyExampleDTO> stats = getStats().stream();
for (FilterParameter filter : queryParameters.getFilter()) {
if (MyExampleDTO_.sum.getName().equals(filter.getName())) {
long bound = filter.getLongValue();
if (filter.getOperation() == SearchOperation.GREATER_OR_EQUAL_THAN) {
stats = stats.filter(dto -> dto.getSum() >= bound);
} else if (filter.getOperation() == SearchOperation.LESS_THAN) {
stats = stats.filter(dto -> dto.getSum() < bound);
}
}
}
return new PageImpl<>(stats.toList());
}
Pagination
not applicable: the chart shows one page, see Page limit.
Export to Excel
not available in this release.
Multi-upload files
not applicable
Sorting
Works only in the table mode for the fields with enableSort in the Meta.
The widget sends the sort to the backend, and the AnySource DAO of the chart applies it itself. After the switch back to the chart, the chart draws the records in the sorted order.
see more Sorting
Page limit
The chart draws only the first page of the business component. When the business component has more records than the page limit,
the chart is not drawn: the widget opens in the table mode, the Chart mode is disabled and a warning icon explains why.
Set the page limit of the business component to the number of points, see Page limit.
How does it look?

How to add?
Example
Step1 Set the page limit in the BC_PROPERTIES table. In the sample it is 4 for 12 points.
Step2 The DAO returns the page asked by the widget. Pageable pageable = PageRequest.of(queryParameters.getPageNumber(), queryParameters.getPageSize());
List<MyExampleDTO> stats = getStats();
int from = (int) Math.min(pageable.getOffset(), stats.size());
int to = Math.min(from + pageable.getPageSize(), stats.size());
return new PageImpl<>(stats.subList(from, to), pageable, stats.size());
No data
When the business component returns no records, the widget shows No Data instead of the chart.
How does it look?

Parent-child
not available in the chart mode in this release: a click on a point does not select the record, the child widgets do not change. In the table mode a click on a row selects the record.