如何从android栏上方删除小数

问题描述 投票:0回答:1

下面代码中的Hi想要更改左yaxis的值,想要显示2的倍数,并且想要在条的上方显示整数。

任何人都可以帮助我

From the below graph how to change float to integer number from above of the graph

private void setData_chart(int count, float range) {

        float barWidth = 0.9f;
        ArrayList<BarEntry> values = new ArrayList<>();

        for (int i = 0; i < count; i++) {
            float val = Math.round((float) (Math.random() * range));
            values.add(new BarEntry(i, val,
                    getResources().getDrawable(R.drawable.ic_launcher)));
        }

        BarDataSet set1;
        if (chart1.getData() != null &&
                chart1.getData().getDataSetCount() > 0) {
            set1 = (BarDataSet) chart1.getData().getDataSetByIndex(0);
            set1.setValues(values);
            chart1.getData().notifyDataChanged();
            chart1.notifyDataSetChanged();
        }
        else {
            set1 = new BarDataSet(values, "");

            int endColor1 = ContextCompat.getColor(getContext(), R.color.linecolor);


            set1.setColors(endColor1);
            set1.setDrawIcons(false);

            dataSets = new ArrayList<>();
            dataSets.add(set1);

            BarData data = new BarData(dataSets);
            data.setValueTextSize(12f);
            data.setValueTypeface(tfLight);
            data.setBarWidth(barWidth);
            chart1.setData(data);
        }
    }
android bar-chart mpandroidchart
1个回答
0
投票

为此,您必须创建单独的ValueFormatter并将其绑定到图表数据。

public class MyDecimalValueFormatter implements ValueFormatter {

        private DecimalFormat mFormat;

        public MyDecimalValueFormatter() {
            mFormat = new DecimalFormat("#");
        }

        @Override
        public String getFormattedValue(float value) {
            return mFormat.format(value);
        }
    }

并按如下所示进行设置

MyDecimalValueFormatter formatter = new MyDecimalValueFormatter();

    BarData data = new BarData(dataSets);
    data.setValueTextSize(12f);
    data.setValueTypeface(tfLight);
    data.setBarWidth(barWidth);
    data.setValueFormatter(formatter)
    chart1.setData(data);
© www.soinside.com 2019 - 2024. All rights reserved.