Здравствуйте, в моем приложении реализована функция отображения гистограммы. Впервые я звоню с гистограммы Api.Next раз и далее для отображения с локальными данными.
В приведенном ниже коде x- Ось содержит имя строки, а ось Y содержит количество каждой строки.
Я создал класс модели и общие настройки для локального хранения данных с использованием общих предпочтений.
Может ли кто-нибудь мне помочь
@SuppressLint("ResourceAsColor")
private void workingOnResponseall(SyncModule syncModule){
//isdate=true;
String success = syncModule.getSuccess();
if (success.equals("true")) {
SyncResults results = syncModule.getResult();
Sync sync = results.getSync();
ArrayList<SyncUpdated> syncUpdateds = sync.getUpdated();
for (SyncUpdated syncUpdated : syncUpdateds) {
ArrayList<SyncBlocks> syncBlocks = syncUpdated.getBlocks();
String scheduleDates = "";
String scheduleDate = "";
String status_list = "";
for (SyncBlocks syncBlocks1 : syncBlocks) {
String label = syncBlocks1.getLabel();
if (label.equals("Task Details")) {
ArrayList<SynFields> synFields = syncBlocks1.getFields();
for (SynFields synFields1 : synFields) {
name = synFields1.getName();
values = synFields1.getValue();
if (name.equals("cf_1015")) {
outcome = String.valueOf(values);
}
}
}
PreferenceManagerMyTask.getInstance(requireContext()).setMultipleDataOutcome(scheduleDate,outcome);
}
MyTaskModel outcomeModel = new MyTaskModel(scheduleDate,outcome);
outcome_list.add(outcome);
Log.d("outcomeModel",outcome);
if(outcome.equals("Order Closed")){
String 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")){
String 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")){
String 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")){
String 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")){
String 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));
}
xAxis.setValueFormatter(new ValueFormatter() {
@Override
public String getFormattedValue(float value) {
if (value < 0 || value > outcome_list.size() - 1) {
return "";
}
String valueStr = String.valueOf(outcome_list);
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(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();
}
}
PreferenceManagerMyTask. java:
public class PreferenceManagerMyTask {
private static PreferenceManagerMyTask jInstance;
private final SharedPreferences prefs;
private final SharedPreferences.Editor editor;
public PreferenceManagerMyTask(Context context) {
prefs = context.getSharedPreferences("Genworks_dashboardtask", Context.MODE_PRIVATE);
editor = prefs.edit();
editor.clear();
editor.apply();
}
public static synchronized PreferenceManagerMyTask getInstance(Context context) {
if (jInstance != null) {
return jInstance;
} else {
jInstance = new PreferenceManagerMyTask(context);
return jInstance;
}
}
public void setAPIResponseDashboardTask(String res){
editor.putString("response",res);
editor.apply();
}
public String getAPIResponseDashboardTask(){
return prefs.getString("response","");
}
public void setMultipleDataOutcome(String scheduleDate,String outcome){
editor.putString("scheduleDate", scheduleDate);
editor.putString("outcome", outcome);
editor.apply(); // btw where you call these values i mean where you use these above value from preferce.
}
public String getScheduleDate(){
return prefs.getString("scheduleDate","");
}
public String getOutcome(){
return prefs.getString("outcome","");
}
}
Класс модели:
public class MyTaskModel {
private String date_start;
private String outcome;
public MyTaskModel(String date_start, String outcome) {
this.date_start = date_start;
this.outcome = outcome;
}
public String getDate_start() {
return date_start;
}
public void setDate_start(String date_start) {
this.date_start = date_start;
}
public String getOutcome() {
return outcome;
}
public void setOutcome(String outcome) {
this.outcome = outcome;
}
}