问题
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