Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
708 views
in Technique[技术] by (71.8m points)

integer - Reset value for the pie chart

Can someone tell me if it is possible to reset the drawing of the piechart?

I created a button to draw the chart with the value inputs from the user, but the problem is: If the user input new numbers and press the button again, the chart doesn't update for the new values.

Can someone tell me how to do that?

My code: =-=-=-=-=-=-=-=-=-=-Start method when the button is pressed-=-=-=-=-=-=-=-=-

        Button calcular = findViewById(R.id.calculargerencia);
    calcular.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.calculargerencia:
                    calculartabela();
                    break;
            }
        }
    });

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Then, the method:

   public void calculartabela(){
    String ganhos1 = ganhos.getText().toString().trim();
    String gastos1 = gastos.getText().toString().trim();

    piechart = findViewById(R.id.piechart);

    Double ganhos = Double.parseDouble(ganhos1);
    Double gastos = Double.parseDouble(gastos1);
    Double restante = ganhos - gastos;

    //apos calculo

    String ganhos2 = ganhos.toString();
    String gastos2 = gastos.toString();
    String restante2 = restante.toString();

    String[] months = {"Ganhos", "Gastos", "Economizado"};
    Double[] earnings = {ganhos, gastos, restante};


    Pie pie = AnyChart.pie();
    List<DataEntry> dataEntries = new ArrayList<>();

    for (int i = 0;
         i < months.length;
         i++) {
        dataEntries.add(new ValueDataEntry(months[i], earnings[i]));

    }

    pie.data(dataEntries);
    piechart.setChart(pie);
question from:https://stackoverflow.com/questions/65646366/reset-value-for-the-pie-chart

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...