Dynamically set x-axis labels are not displaying in android

时间秒杀一切 提交于 2020-05-24 05:47:10

问题


Hi in the below code I was implemented barchart using library called Mpandroidchart.Dyanmically I am setting the Labels for x-axis.But lables are not displaying for the x-axis.

Below is my code task types are the list of the string that strings are I am trying to set labels for X-axis.

chart1 = rootView.findViewById(R.id.chart11);
     xl.setValueFormatter(new IndexAxisValueFormatter(getTaskCount()));
    public ArrayList<String> getTaskCount() {

            ArrayList<String> label = new ArrayList<>();
            for (int i = 0; i < taskTypes.size(); i++)
                label.add(taskTypes.get(i));
            return label;
        }
     private void setData(int count, float range) {

            float barWidth = 9f;
            float spaceForBar = 10f;
            ArrayList<BarEntry> values = new ArrayList<>();

            for (int i = 0; i < count; i++) {
                float val = (float) (Math.random() * range);
                values.add(new BarEntry(i * spaceForBar, 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, "DataSet 1");

                set1.setDrawIcons(false);

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

                BarData data = new BarData(dataSets);
                data.setValueTextSize(10f);
                data.setValueTypeface(tfLight);
                data.setBarWidth(barWidth);
                chart1.setData(data);
                chart1.setFitBars(true);
            }
        }

来源:https://stackoverflow.com/questions/61163389/dynamically-set-x-axis-labels-are-not-displaying-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!