Search code examples
javaandroidnumber-formattingdecimalformatanychart

AnyChart on Android: Format x-Axis values


I am currently working with AnyChart on Android for the first time. The data is displayed correctly and everythings working so far. But I cannot format the values on the x-Axis.

I tried to use

cartesian2.xAxis(0).labels("{%Value}{numDecimals:2}");

But it does not have any effect. I just want two decimal digits. I did not find any solution online as most of the documentation is about JS.

EDIT:

 APIlib.getInstance().setActiveAnyChartView(brightplot);

        List<DataEntry> brightnessdata = createSeries(maxBrightnessRow);


        Cartesian cartesian2 = AnyChart.column();

        cartesian2.data(brightnessdata);

        cartesian2.title("Intensitätsverteilung");

        cartesian2.yScale().minimum(0d);
        cartesian2.yScale().maximum(255);

        cartesian2.xAxis(0).title("Ort [cm]");

        cartesian2.yAxis(0).title("Intensität");

        cartesian2.xScroller(true);
        cartesian2.xZoom(true);
        cartesian2.yAxis(0).labels(false);

        cartesian2.xZoom().setToPointsCount(1500,false, null);
        cartesian2.xAxis(0).labels().format("{%Value}{decimalsCount:2}");

        brightplot.setHorizontalScrollBarEnabled(true);
        brightplot.setVerticalScrollBarEnabled(true);
        brightplot.setZoomEnabled(true);
        brightplot.setChart(cartesian2);
        brightplot.setVisibility(View.VISIBLE);

Solution

  • The problem is that x values should have "number" type, so to make it all work, please write the following line: chart.xAxis().labels().format("{%value}{type:number, decimalsCount:2}");