Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...