Column2D
Column2D widget draws a column chart: one bar per category on the X axis, a number on the Y axis.
Several bars per category 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 bar of the chart. The widget takes the bar from two fields:
xValueFieldKey: the field with the category on the X axis (a client, a month, a product).yValueFieldKey: the numeric field with the height of the bar 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 bars of a category. One bar per value, the values are shown in the legend. See Groups. |
stack |
no | true puts the bars of a category 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 bar: the X value and the Y value.
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class MyExampleDTO extends DataResponseDTO {
private String clientName;
private Long sum;
}
Step2 Create DAO extends AbstractAnySourceBaseDAO<> implements AnySourceBaseDAO.
The DAO returns one record per bar, sorted along the X axis, with a unique id.
@NonNull
private List<MyExampleDTO> getStats() {
return repository.getClientSums().stream()
.map(stat -> {
MyExampleDTO dto = new MyExampleDTO()
.setClientName(stat.clientName())
.setSum(stat.sum());
dto.setId(stat.id().toString());
return dto;
}).toList();
}
@Query("""
SELECT new org.demo.documentation.widgets.columnd.data.ClientSum(
min(e.id), e.clientName, sum(e.amount), count(e.id))
FROM MyEntity e
GROUP BY e.clientName
ORDER BY e.clientName
""")
List<ClientSum> getClientSums();
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 = "Column2D".
Add the fields of the bar and options.chart2D with xValueFieldKey and yValueFieldKey.
{
"name": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum"
}
}
}
Step6 Add widget to corresponding .view.json.
{
"name": "myexamplecolumnd",
"title": "ColumnD",
"url": "/screen/myexample/view/myexamplecolumnd",
"template": "DashboardView",
"widgets": [
{
"widgetName": "myexamplecolumnd",
"position": 10,
"gridWidth": 24
}
],
"rolesAllowed": [
"CXBOX_USER"
]
}
Step7 Set the page limit of the business component to the number of bars, 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": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum"
}
}
}
Step1 Delete parameter title from .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 bars (for example, a sum per client)
and returns them in the order of the X axis. One record is one bar, 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 the field of the condition to the DataResponseDTO of the other business component.
Step2 Add showCondition to .widget.json. see more showCondition{
"name": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum"
}
},
"showCondition": {
"bcName": "myExampleBcForm",
"params": {
"fieldKey": "customFieldShowCond",
"value": "true"
}
}
}
Fields
Fields Configuration. The fields array defines the fields of a bar. 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": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"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 bar. By default it shows the X value and the value of every bar of the category.
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 Fill the description field in the DAO.
@NonNull
private List<MyExampleDTO> getStats() {
return repository.getClientSums().stream()
.map(stat -> {
MyExampleDTO dto = new MyExampleDTO()
.setClientName(stat.clientName())
.setSum(stat.sum())
.setDescription(stat.clientName() + ": " + stat.count() + " sales");
dto.setId(stat.id().toString());
return dto;
}).toList();
}
{
"name": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Description",
"key": "description",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum",
"descriptionFieldKey": [
"description"
]
}
}
}
Color
The color of the bars is set on the X field:
bgColorKey: the key of the field with the color of the record. The color is set per group: all bars of a group take the color of its first record. WithoutgroupFieldKeyall bars have one color.bgColor: one constant color for all bars.
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.getClientProductSums().stream()
.map(stat -> {
MyExampleDTO dto = new MyExampleDTO()
.setClientName(stat.clientName())
.setProductName(stat.product().getValue())
.setSum(stat.sum())
.setColor(stat.product() == MyEntityProduct.EXPERTISE ? "#30BAF" : "#EDAA");
dto.setId(stat.id().toString());
return dto;
}).toList();
}
{
"name": "myexamplecolumnd",
"title": "Sales per client and product",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input",
"bgColorKey": "color"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum",
"groupFieldKey": "productName"
}
}
}
Step1 Add bgColor to the X field in .widget.json.
{
"name": "myexamplecolumndcolorconst",
"title": "Sales per client and product",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input",
"bgColor": "#EDAA"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum",
"groupFieldKey": "productName"
}
}
}
Drilldown
A click on a bar opens the view with the records behind the bar. 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 bar knows its group, 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": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input",
"drillDown": true
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum"
}
}
}
@Override
public void buildRowDependentMeta(RowDependentFieldsMeta<MyExampleDTO> fields, BcDescription bc,
String id, String parentId) {
String clientName = repository.getReferenceById(Long.parseLong(id)).getClientName();
fields.setDrilldownWithFilter(
MyExampleDTO_.clientName,
DrillDownType.INNER,
"/screen/myexample/view/myexamplesales",
fc -> fc.add(
PlatformMyExampleController.myExampleBcSale,
MyExampleSaleDTO.class,
fb -> fb.input(MyExampleSaleDTO_.clientName, clientName)
)
);
}
@Getter
@Setter
@NoArgsConstructor
public class MyExampleSaleDTO extends DataResponseDTO {
@SearchParameter(name = "clientName")
private String clientName;
@SearchParameter(name = "product", provider = EnumValueProvider.class)
private MyEntityProduct product;
@SearchParameter(name = "amount")
private Long amount;
public MyExampleSaleDTO(MyEntity entity) {
this.id = entity.getId().toString();
this.clientName = entity.getClientName();
this.product = entity.getProduct();
this.amount = entity.getAmount();
}
}
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 bars of a category: one bar per value of the field, side by side. The values are shown in the legend.
A click on a legend value hides or shows its bars.
Without groupFieldKey the chart has one bar per category, 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.
{
"name": "myexamplecolumnd",
"title": "Sales per client and product",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum",
"groupFieldKey": "productName"
}
}
}
Stack
stack: true puts the bars of a category one on top of the other: the height of the column is the sum of the group values.
Use it with groupFieldKey.
How does it look?

How to add?
Example
Step1 Add stack to options.chart2D in .widget.json.
{
"name": "myexamplecolumndstack",
"title": "Sales per client and product",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
},
{
"title": "Product",
"key": "productName",
"type": "input"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"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": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum",
"yMin": 0,
"yMax": 6000,
"yStep": 1500
}
}
}
DualAxes2D
A Column2D widget can be combined with a Line2D 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 does it look?

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
public class MyExampleDTO extends DataResponseDTO {
@SearchParameter(name = "parentId", provider = LongValueProvider.class)
private Long parentId;
private Boolean isLeaf;
@SearchParameter(name = "customField")
private String customField;
@SearchParameter(name = "customFieldNew")
private String customFieldNew;
@SearchParameter(name = "customFieldMultivalueList.id", provider = LongValueProvider.class)
private MultivalueField customFieldMultivalue;
private String customFieldMultivalueDisplayedKey;
@SearchParameter(name = "customFieldPicklistEntity.customField")
private String customFieldPicklist;
@SearchParameter(name = "customFieldPicklistEntity.id", provider = LongValueProvider.class)
private Long customFieldPicklistId;
public MyExampleDTO(MyEntity entity) {
this.id = entity.getId().toString();
this.parentId = entity.getParentId();
this.isLeaf = entity.getChildren().isEmpty();
this.customField = entity.getCustomField();
this.customFieldNew = entity.getCustomFieldNew();
this.customFieldMultivalue = entity.getCustomFieldMultivalueList().stream().collect(MultivalueField.toMultivalueField(
e -> String.valueOf(e.getId()),
e -> String.valueOf(e.getCustomField())
));
this.customFieldMultivalueDisplayedKey = StringUtils.abbreviate(entity.getCustomFieldMultivalueList().stream().map(MyEntity::getCustomField
).map(e -> e.toString()).collect(Collectors.joining(",")), 12);
this.customFieldPicklistId = Optional.ofNullable(entity.getCustomFieldPicklistEntity())
.map(e -> e.getId())
.orElse(null);
this.customFieldPicklist = Optional.ofNullable(entity.getCustomFieldPicklistEntity())
.map(e -> e.getCustomField())
.orElse(null);
}
}
Step 2 Add fields.enableFilter to corresponding FieldMetaBuilder.
@Override
public void buildIndependentMeta(FieldsMeta<MyExampleDTO> fields, InnerBcDescription bcDescription, Long parentId) {
fields.enableFilter(MyExampleDTO_.parentId);
fields.enableFilter(MyExampleDTO_.customFieldPicklist);
fields.enableFilter(MyExampleDTO_.customFieldMultivalue);
fields.enableFilter(MyExampleDTO_.customFieldNew);
fields.enableFilter(MyExampleDTO_.customField);
fields.enableSort(MyExampleDTO_.customFieldNew);
fields.enableSort(MyExampleDTO_.customField);
}
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_.clientName.getName().equals(filter.getName())
&& filter.getOperation() == SearchOperation.CONTAINS) {
stats = stats.filter(dto -> Strings.CI.contains(dto.getClientName(), 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 does it look?

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.getClientName(), value)).orElse(true))
.toList());
}
Step 3 Add fullTextSearch to corresponding .widget.json.
enabled true/false
placeholder - description for fullTextSearch
{
"name": "myexamplecolumnd",
"title": "Sales per client",
"type": "ColumnD",
"bc": "myExampleBc",
"fields": [
{
"title": "Client",
"key": "clientName",
"type": "input"
},
{
"title": "Sum, $",
"key": "sum",
"type": "number"
}
],
"options": {
"chartD": {
"xValueFieldKey": "clientName",
"yValueFieldKey": "sum"
},
"fullTextSearch": {
"enabled": true,
"placeholder": "Find by client"
}
}
}
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 does it look?

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 4000;myExampleBc4270;sum.greaterOrEqualThan=4000;
Sum under 4000;myExampleBc4270;sum.lessThan=4000;
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 bars, 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 3 for 5 bars.
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 bar does not select the record, the child widgets do not change. In the table mode a click on a row selects the record, and the child widgets show the data of this record.