Reputation: 307
here is my code for showing text lable for displaying data in pie chart now i want to hide text lable value if data is not preasent for perticular text value, how can i achive that below is my code
final ArrayList<PieEntry> yEntrys = new ArrayList<>();
//List<String> entries = new ArrayList<>();
Toast.makeText(getContext(), "Toase"+response.toString(), Toast.LENGTH_SHORT).show();
Log.d("pieData",response.toString());
try {
JSONArray jsonarray = (JSONArray) response.get("piechartlist");
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String messageSent = jsonobject.getString("messageSent").trim();
String failed = jsonobject.getString("failed").trim();
String rejected = jsonobject.getString("rejected").trim();
String expired = jsonobject.getString("expired").trim();
String unDelivered = jsonobject.getString("unDelivered");
String delivered = jsonobject.getString("delivered");
String ndnc = jsonobject.getString("ndnc");
yEntrys.add(new PieEntry(Integer.valueOf(messageSent), "messageSent"));
yEntrys.add(new PieEntry(Integer.valueOf(failed), "failed"));
yEntrys.add(new PieEntry(Integer.valueOf(rejected), "rejected"));
yEntrys.add(new PieEntry(Integer.valueOf(expired), "expired"));
yEntrys.add(new PieEntry(Integer.valueOf(unDelivered), "unDelivered"));
yEntrys.add(new PieEntry(Integer.valueOf(delivered), "delivered"));
yEntrys.add(new PieEntry(Integer.valueOf(ndnc), "ndnc"));
}
} catch (JSONException e) {
e.printStackTrace();
}
Upvotes: 0
Views: 1928
Reputation: 793
Just don't add the Entry to the PieChart.
if (Integer.valueOf(messageSent) > 0)
{
yEntrys.add(new PieEntry(Integer.valueOf(messageSent), "messageSent"));
}
btw: your JSON parsing is kinda wired. I would suggest POJOs and GSON for parsing JSON Strings.
Upvotes: 2