How to set the new value about y in a mpandroidchart barchart

61 views Asked by At

At first My y value are these:

                arrayList1.add("math");
                arrayList1.add("english");
                arrayList1.add("biology");
                arrayList1.add("computer");
                arrayList1.add("java");
                arrayList1.add("c");
 //fake data
                for (int i = 0; i < arrayList1.size(); i++) {
                    score_array.add((float) 0);
                }
 ValueFormatter valueFormatter=new ValueFormatter() {
                    @Override
                    public String getFormattedValue(float value) {
                        if (value>=0){
                            return arrayList1.get((int) value);
                        }
                        else{
                            return "";
                        }
                    }
                };
                xAxis.setValueFormatter(valueFormatter);
                                
               arrayList_BarEntry=Set_BarChar_Data(score_array,null);


But When I click a button I want to change my y value to

                arrayList1.clear();
                arrayList1.add("english");
                arrayList1.add("biology");
                arrayList1.add("c#");
                arrayList1.add("python");
                arrayList1.add("biology");
                arrayList1.add("math");
               for (int i = 0; i < arrayList1.size(); i++) {
                    score_array.add((float) 100);
                }
               arrayList_BarEntry=Set_BarChar_Data(score_array,null);


How can i do it

I want to change x value and y value

add bar value function




ArrayList<BarEntry> Set_BarChar_Data(@NotNull ArrayList<Float>score_array,@Nullable Integer high_position){
        ArrayList<BarEntry> values = new ArrayList<>();
        for (int i = 0; i < score_array.size(); i++) {
            values.add(new BarEntry((float) i, score_array.get(i)));
        }
        BarDataSet set1;
        if (teacher_score_barchart.getData() != null &&
                teacher_score_barchart.getData().getDataSetCount() > 0) {
            set1 = (BarDataSet) teacher_score_barchart.getData().getDataSetByIndex(0);
            set1.setValues(values);
            if (high_position!=null){
                set1.setHighLightColor(lessons_colors.get(high_position));
            }
            teacher_score_barchart.getData().notifyDataChanged();
            teacher_score_barchart.notifyDataSetChanged();
        } else {
            set1 = new BarDataSet(values,"score");
            set1.setColors(lessons_colors);
            set1.setDrawValues(false);
            ArrayList<IBarDataSet> dataSets = new ArrayList<>();
            dataSets.add(set1);
            BarData data = new BarData(dataSets);
            teacher_score_barchart.setData(data);
            teacher_score_barchart.setFitBars(true);
        }
        //draw chart
        teacher_score_barchart.invalidate();
        teacher_score_barchart.animateXY(1000,1000);
        return values;
    }



I want to change the x and y axis values At first the barchart x and y values are

  • math->20
  • english->50
  • biology->100

at the beginning. When I click the button, it becomes

  • pe->50
  • java->100
  • english->20
  • c->100
0

There are 0 answers