Как поместить данные в Piechart MPAndroidChart

вчера я попытался поместить данные (десятичное число, строка) в Piechart MPAndroidchart, но у меня возникла проблема, когда я добавил поле Stock (десятичное число) и item_name (String) в «yEntrys.add (new PieEntry (.. .)", то оба не отображаются. Еще раз, если добавить одно поле item_name(String) только в "yEntrys.add(new PieEntry(...)", оно отображается без запаса, и это сбивает меня с толку из-за этой проблемы. данные я использую метод "GET" модификации2).

Это некоторые данные в формате json из базы данных, и они динамические:

{"success":true,
    "result":
        [{"id":"1","item_name":"Salt","stock":"6.5"},
         {"id":"2","item_name":"Sugar","stock":"50.8"},
         {"id":"3","item_name":"Coffe ","stock":"40"},
         {"id":"4","item_name":"Rice","stock":"30.8"
         }]
}

этот мой код в ListActivity:

ItemService itemService = APIClient.getClient().create(ItemService .class);
Call<responseItem > call = itemService.getFindAll();
ResponseItem responseItem = response.body();
    if (responseItem.getSuccess().equals("true")) {
        itemList = response.body().getResult();
        List<Item> itemList = new ArrayList<>();
        ArrayList<PieEntry> yEntrys = new ArrayList<PieEntry>();

        for (int i = 0; i < itemList.size(); i++) {
        //this is place i added some field
        yEntrys.add(new PieEntry(i, itemList .get(i).getStock(), itemList.get(i).getItem_name()));

        }

        PieDataSet dataset = new PieDataSet(yEntrys,null);
        dataset.setSliceSpace(3);
        dataset.setValueTextSize(5);

        ArrayList<Integer> colors = new ArrayList<Integer>();

        for (int c : ColorTemplate.VORDIPLOM_COLORS)
        colors.add(c);

        for (int c : ColorTemplate.JOYFUL_COLORS)
        colors.add(c);

        for (int c : ColorTemplate.COLORFUL_COLORS)
        colors.add(c);

        for (int c : ColorTemplate.LIBERTY_COLORS)
        colors.add(c);

        for (int c : ColorTemplate.PASTEL_COLORS)
        colors.add(c);

        colors.add(ColorTemplate.getHoloBlue());
        dataset.setColors(colors);

        Legend legend = pieChart.getLegend();
        legend.setForm(Legend.LegendForm.DEFAULT);
        legend.setPosition(Legend.LegendPosition.LEFT_OF_CHART);
        legend.setTextSize(8);

        Description description = new Description();
        description.setText("Stocks Description of Items");

        pieChart.setDescription(description);  
        description.setTextColor(Color.BLUE);
        pieChart.setRotationEnabled(true);

        pieChart.setHoleRadius(25f);
        pieChart.setTransparentCircleAlpha(0);
        pieChart.setCenterText("Chart");
        pieChart.setCenterTextSize(10);
        pieChart.setDrawEntryLabels(true);
        pieChart.setEntryLabelTextSize(5);
        pieChart.setTransparentCircleColor(5);

        pieData = new PieData(dataset);
        pieData.setValueTextColor(Color.BLUE);
        pieChart.setData(pieData);
        pieChart.animateY(2000);
        pieChart.highlightValues(null);
        pieChart.invalidate();

        }else{
    Toast.makeText(ListActivity.this, responseItem.getSuccess(), Toast.LENGTH_SHORT).show();
    }

Мой ответ: Как решить эту проблему. Спасибо всем.


person crazycoder    schedule 21.08.2018    source источник
comment
Привет старший программист, мне нужна помощь, спасибо.   -  person crazycoder    schedule 21.08.2018
comment
может ли кто-нибудь помочь мне решить эту проблему?   -  person crazycoder    schedule 22.08.2018
comment
Попробуйте это: stackoverflow.com/ вопросы/41582586/   -  person EMPaguia    schedule 10.10.2018