条形图上未设置Volley响应数据

时间:2018-07-09 06:44:14

标签: java android github graph

我想在我的应用程序片段上实现条形图,其中数据将来自截击响应。我正在将compile 'com.github.PhilJay:MPAndroidChart:v2.2.4'库用于图形。数据即将响应并将其成功拆分,但是当我将数据放在条形图上时,它显示为空。请检查我的代码,并帮助我解决此问题。预先谢谢你

public class MonthsFragment extends Fragment {

public String user_id;
// Session Manager Class
UserSessionManager session;

BarChart chartUniqueVisitors;
ArrayList<BarEntry> BARENTRY ;
ArrayList<String> BarEntryLabels ;
BarDataSet Bardataset ;
BarData BARDATA ;

public float jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec;

public MonthsFragment(){}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view= inflater.inflate(R.layout.fragment_unique_visitors, container, false);

    session = new UserSessionManager(getContext());
    session.checkLogin();
    // get user data from session
    HashMap<String, String> user = session.getUserDetails();
    user_id = user.get(UserSessionManager.KEY_USER_ID);

    return view;
}


public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);
    chartUniqueVisitors = (BarChart) v.findViewById(R.id.chartUniqueVisitors);

    BARENTRY = new ArrayList<>();
    BarEntryLabels = new ArrayList<String>();

    getDataForBusinessAddress();
    AddValuesToBARENTRY();
    AddValuesToBarEntryLabels();

    Bardataset = new BarDataSet(BARENTRY, "Projects");

    BARDATA = new BarData(BarEntryLabels, Bardataset);

    Bardataset.setColors(ColorTemplate.COLORFUL_COLORS);

    chartUniqueVisitors.setData(BARDATA);

    chartUniqueVisitors.animateY(3000);
}

用于从服务器获取数据的功能

private void getDataForBusinessAddress() {
    String getBusinessAddressURL ="xyz.php?username="+user_id;
    StringRequest stringRequest = new StringRequest(Request.Method.POST,getBusinessAddressURL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            JSONArray jsonarray = null;
            try {
                jsonarray = new JSONArray(response);
                for (int i = 0; i < jsonarray.length(); i++) {
                    JSONObject jsonobject = jsonarray.getJSONObject(i);
                    jan = Float.parseFloat(jsonobject.getString("Jan"));
                    feb = Float.parseFloat(jsonobject.getString("Feb"));
                    mar = Float.parseFloat(jsonobject.getString("Mar"));
                    apr = Float.parseFloat(jsonobject.getString("Apr"));
                    may = Float.parseFloat(jsonobject.getString("May"));
                    jun = Float.parseFloat(jsonobject.getString("Jun"));
                    jul = Float.parseFloat(jsonobject.getString("Jul"));
                    aug = Float.parseFloat(jsonobject.getString("Aug"));
                    sep = Float.parseFloat(jsonobject.getString("Sep"));
                    oct = Float.parseFloat(jsonobject.getString("Oct"));
                    nov = Float.parseFloat(jsonobject.getString("Nov"));
                    dec = Float.parseFloat(jsonobject.getString("Dece"));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(getContext(),error.getMessage().toString(),Toast.LENGTH_LONG).show();
                }
            });

    RequestQueue requestQueue = Volley.newRequestQueue(getContext());
    requestQueue.getCache().clear();
    requestQueue.add(stringRequest);
}

用于在BarEntry上设置数据的功能。我尝试在此处登录,但数据没有发送到

public void AddValuesToBARENTRY(){
    BARENTRY.add(new BarEntry(jan, 0));
    BARENTRY.add(new BarEntry(feb, 1));
    BARENTRY.add(new BarEntry(mar, 2));
    BARENTRY.add(new BarEntry(apr, 3));
    BARENTRY.add(new BarEntry(may, 4));
    BARENTRY.add(new BarEntry(jun, 5));
    BARENTRY.add(new BarEntry(jul, 6));
    BARENTRY.add(new BarEntry(aug, 7));
    BARENTRY.add(new BarEntry(sep, 8));
    BARENTRY.add(new BarEntry(oct, 9));
    BARENTRY.add(new BarEntry(nov, 10));
    BARENTRY.add(new BarEntry(dec, 11));
}

在条形图中设置名称的功能

public void AddValuesToBarEntryLabels(){
    BarEntryLabels.add("Jan");
    BarEntryLabels.add("Feb");
    BarEntryLabels.add("Mar");
    BarEntryLabels.add("Apr");
    BarEntryLabels.add("May");
    BarEntryLabels.add("Jun");
    BarEntryLabels.add("Jul");
    BarEntryLabels.add("Aug");
    BarEntryLabels.add("Sep");
    BarEntryLabels.add("Oct");
    BarEntryLabels.add("Nov");
    BarEntryLabels.add("Dec");
  }
}      

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

 I/ActivityManager: START u0 {act=com.linkedin.android.auth.AUTHORIZE_APP 
 cat=[com.linkedin.android.auth.thirdparty.authorize] 
 cmp=com.linkedin.android/.liauthlib.thirdparty.LiThirdPartyAuthorizeActivity 
(has extras)} from uid 11044 on display 0
D/EventBus: No subscribers registered for event class 
com.linkedin.android.messaging.realtime.RealTimeConnectionChangedEvent
D/EventBus: No subscribers registered for event class 
org.greenrobot.eventbus.NoSubscriberEvent
W/Binder_F: type=1400 audit(0.0:1418): avc: denied { ioctl } for 
path="socket:[116828]" dev="sockfs" ino=116828 ioctlcmd=7704 
scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 
tclass=unix_stream_socket permissive=0
D/EventBus: No subscribers registered for event class 
com.linkedin.android.infra.events.NetworkConnectionChangedEvent
D/EventBus: No subscribers registered for event class 
org.greenrobot.eventbus.NoSubscriberEvent
W/Binder_F: type=1400 audit(0.0:1419): avc: denied { ioctl } for 
path="socket:[116828]" dev="sockfs" ino=116828 ioctlcmd=7704 
scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 
tclass=unix_stream_socket permissive=0
W/Binder_C: type=1400 audit(0.0:1420): avc: denied { ioctl } for 
path="socket:[94116]" dev="sockfs" ino=94116 ioctlcmd=7704 
scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 
tclass=unix_stream_socket permissive=0
W/Binder_C: type=1400 audit(0.0:1421): avc: denied { ioctl } for 
path="socket:[94116]" dev="sockfs" ino=94116 ioctlcmd=7704 
scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 
tclass=unix_stream_socket permissive=0
I/ActivityManager: Displayed 
com.linkedin.android/.liauthlib.thirdparty.LiThirdPartyAuthorizeActivity: 
+298ms
D/EventBus: No subscribers registered for event class 
com.linkedin.android.messaging.realtime.RealTimeConnectionChangedEvent
D/EventBus: No subscribers registered for event class 
org.greenrobot.eventbus.NoSubscriberEvent
I/System.out: login_error{
/System.out:   "errorCode": "INVALID_REQUEST",
I/System.out:   "errorMessage": "either bundle id or package name \/ hash are 
invalid, unknown, malformed"
I/System.out: }
W/Binder_D: type=1400 audit(0.0:1422): avc: denied { ioctl } for 
path="socket:[112610]" dev="sockfs" ino=112610 ioctlcmd=7704 
scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 
tclass=unix_stream_socket permissive=0
W/Binder_D: type=1400 audit(0.0:1423): avc: denied { ioctl } for 
path="socket:[112610]" dev="sockfs" ino=112610 ioctlcmd=7704 
scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 
tclass=unix_stream_socket permissive=0
D/EventBus: No subscribers registered for event class 
com.linkedin.android.messaging.realtime.RealTimeConnectionChangedEvent
D/EventBus: No subscribers registered for event class 
org.greenrobot.eventbus.NoSubscriberEvent
D/EventBus: No subscribers registered for event class 
com.linkedin.android.messaging.realtime.RealTimeConnectionChangedEvent
D/EventBus: No subscribers registered for event class 
org.greenrobot.eventbus.NoSubscriberEvent

我希望这段代码对您有帮助