Add custom theme for charts

Hi there,

According to the amcharts documentation we can use any custom theme.

Unfortunately, I’ve got the following error when trying to use a custom theme* in the chart:
IllegalArgumentException: No enum constant com.haulmont.charts.gui.amcharts.model.ChartTheme.myTheme

*I’ve added the following line in my screen xml file: theme="myTheme"

Seems that available themes are predefined, so what is the way to add my own?

Hi,

You’re right, the theme attribute supports only default themes. In case of custom theme, you can set the theme name using the setNativeJson method:

public class LineChartController extends AbstractFrame {
    @Inject
    private SerialChart lineChart;

    @Override
    public void init(Map<String, Object> params) {
        lineChart.setNativeJson("{\"theme\": \"dark\"}");
    }
}

Regards,
Gleb

1 Like

By the way, nativeJson element is also available in XML:

<chart:serialChart id="serialChart">
    <chart:nativeJson>
        <![CDATA[
        {
            "titles": [
                {
                    "size": 15,
                    "text": "Chart Title"
                }
            ]
        }
        ]]>
    </chart:nativeJson>
    <chart:valueAxes>
        <chart:axis axisAlpha="0" position="LEFT" title="Incidents"/>
    </chart:valueAxes>
    <chart:graphs>
        <chart:graph id="g1" bullet="ROUND" type="COLUMN" valueField="value"/>
    </chart:graphs>
    <chart:categoryAxis position="TOP" title="Time" labelsEnabled="false"/>
</chart:serialChart>

See also Configuration using JSON - CUBA Platform. Displaying Charts And Maps

1 Like