Привет ниже. Я пытался динамически реализовать гистограмму. Но это не дает никакой ошибки. Данные диаграммы не отображаются. Метки X-оси и Y-метки отображаются динамически из Api. output_list - это список класса модели с именем
private ArrayList<MyTaskModel> outcome_list;
«Данные диаграммы недоступны». Это вывод, который я получаю с помощью приведенного ниже кода.
if (name.equals("cf_1015")) {
outcome = String.valueOf(values);
}
}
}
PreferenceManagerMyTask.getInstance(requireContext()).setMultipleDataOutcome(scheduleDate,outcome);
}
MyTaskModel outcomeModel = new MyTaskModel(scheduleDate,outcome);
outcome_list.add(outcomeModel);
// Log.d("outcomeModel",outcome);
if(outcome.equals("Order Closed")){
OrderClosed= outcomeModel.getOutcome();
Log.d("Order Closed", OrderClosed);
Count_OrderClosed = Collections.frequency(outcome_list, "Order Closed");
Log.d("Count Order Closed", String.valueOf(Count_OrderClosed));
}else if(outcome.equals("Follow-up")){
Followup= outcomeModel.getOutcome();
Log.d("Followup", Followup);
Count_Followup = Collections.frequency(outcome_list, "Follow-up");
Log.d("Count_Followup", String.valueOf(Count_Followup));
}else if(outcome.equals("Interested")){
Interested= outcomeModel.getOutcome();
Log.d("Interested", Interested);
Count_Interested1 = Collections.frequency(outcome_list, "Interested");
Log.d("Count_Interested1", String.valueOf(Count_Interested1));
}else if(outcome.equals("Done")){
Done= outcomeModel.getOutcome();
Log.d("Done", Done);
Count_Done = Collections.frequency(outcome_list, "Done");
Log.d("Count_Done", String.valueOf(Count_Done));
}else if(outcome.equals("Collected")){
Collected= outcomeModel.getOutcome();
Log.d("Collected", Collected);
Count_Collected = Collections.frequency(outcome_list1, "Collected");
Log.d("Count_Collected", String.valueOf(Count_Done));
}else if(outcome.equals("Not Interested")){
Not_Interested= outcomeModel.getOutcome();
Log.d("Not_Interested", Not_Interested);
Count_NotInterested = Collections.frequency(outcome_list1, "Not Interested");
Log.d("Count_NotInterested", String.valueOf(Count_NotInterested));
}
final ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add(OrderClosed);
arrayList.add(Not_Interested);
arrayList.add(Collected);
arrayList.add(Done);
arrayList.add(Interested);
arrayList.add(Followup);
Log.d("arraylist", String.valueOf(arrayList));
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if (value < 0 || value > arrayList.size() - 1) {
return "";
}
String valueStr = String.valueOf(arrayList);
String[] outcomeList = valueStr.replace("[", "").replace("]", "").split(",");
return outcomeList[(int) value];
}
});
xAxis.setGranularity(1);
xAxis.setTextSize(10f);
xAxis.setLabelRotationAngle(-90f);
xAxis.setLabelCount(outcome_list.size());
xAxis.setGranularityEnabled(true);
float barWidth = 0.9f;
// String[] mStringArray = new String[outcome_list.size()];
// mStringArray = outcome_list.toArray(mStringArray);
// System.out.println(mStringArray);
ArrayList<BarEntry> values = new ArrayList<>();
values.add(new BarEntry(Float.parseFloat(arrayList.get(0)), Count_Interested1));
values.add(new BarEntry(1, Count_Followup));
values.add(new BarEntry(2, Count_OrderClosed));
values.add(new BarEntry(3, Count_Done));
values.add(new BarEntry(4, Count_Collected));
values.add(new BarEntry(5, Count_NotInterested));
BarDataSet set1;
if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet) chart.getData().getDataSetByIndex(0);
set1.setValues(values);
chart.getData().notifyDataChanged();
chart.notifyDataSetChanged();
chart.invalidate();
} else {
set1 = new BarDataSet(values, "Outcome");
int endColor1 = ContextCompat.getColor(getContext(), R.color.linecolor);
set1.setColors(endColor1);
set1.setDrawIcons(false);
dataSets = new ArrayList<>();
dataSets.add(set1);
MyDecimalValueFormatter formatter = new MyDecimalValueFormatter();
BarData data = new BarData(dataSets);
data.setValueTextSize(12f);
data.setValueFormatter(formatter);
data.setValueTypeface(tfLight);
data.setBarWidth(barWidth);
chart.setData(data);
chart.invalidate();
}