Barchart. title not is not injected in controller

I have a fragment with a barchart that has a title.

In order to change the title programmatically I have it injected into the controller. The title is not injected and the value is null, leading to a NPE.

Perhaps the title is not something that can be injected. In that case studio should not allow injecting it through context actions.

This brings us to the question: what exactly can and cannot be injected? How can we know this?

image

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<fragment xmlns="http://jmix.io/schema/flowui/fragment" xmlns:charts="http://jmix.io/schema/charts/ui">
    <data>
        <collection id="keyValuesDc" class="com.agnicio.web.component.kpi.entity.KeyValueKpiEntity"/>
    </data>
    <content>
        <vbox id="root" classNames="kpi-fragment">
            <charts:chart id="chart" width="200px" height="200px" minHeight="30em">
                <charts:title id="title" right="10%"/>
                <charts:legend/>
                <charts:tooltip trigger="AXIS">
                    <charts:axisPointer type="SHADOW"/>
                </charts:tooltip>
                <charts:xAxes>
                    <charts:xAxis/>
                </charts:xAxes>
                <charts:yAxes>
                    <charts:yAxis/>
                </charts:yAxes>
                <charts:dataSet>
                    <charts:source dataContainer="keyValuesDc" categoryField="key" valueFields="value"/>
                </charts:dataSet>
                <charts:series>
                    <charts:bar name="# violated constraints"/>
                </charts:series>
            </charts:chart>
        </vbox>
    </content>
</fragment>
package com.agnicio.web.component.kpi.view.barchartkpifragment.barchartkpifragment;

import com.agnicio.web.component.kpi.entity.KeyValueCollectionKpiEntity;
import com.agnicio.web.component.kpi.entity.KeyValueKpiEntity;
import com.agnicio.web.component.kpi.view.Kpifragment;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import io.jmix.chartsflowui.component.Chart;
import io.jmix.chartsflowui.kit.component.model.Title;
import io.jmix.flowui.fragment.Fragment;
import io.jmix.flowui.fragment.FragmentDescriptor;
import io.jmix.flowui.model.CollectionContainer;
import io.jmix.flowui.view.ViewComponent;

@FragmentDescriptor("bar-chart-kpi-fragment.xml")
public class BarChartKpiFragment extends Fragment<VerticalLayout> implements Kpifragment<KeyValueCollectionKpiEntity> {
    @ViewComponent
    private CollectionContainer<KeyValueKpiEntity> keyValuesDc;
    @ViewComponent
    private Chart chart;
    @ViewComponent
    private Title title;

    public void setEntity(KeyValueCollectionKpiEntity entity) {
        keyValuesDc.setItems(entity.getKeyValues());
    }
}

Hi,

Thank you for reporting the problem, I’ve created a GitHub issue.

As a general rule, only components (UI, Data) and actions can be injected, while other nested elements simply reflect component settings and cannot be injected.

Regards,
Gleb