javaandroidanychart

How to update chart (anyChart Android) with new data from web service?


I have a cartesian-column chart and I need to refresh the chat with new data from a web service, it works fine the first time but after receiving new data the chart "fuses" the old and new data for a second, then flashes back and shows the old data

Here I clean my DataEntry and call my soap, this is done inside a function that is called from a button

 dataGraf=new ArrayList<>(); 
 new acIndicadores.call_SOAP().execute();

Soap ask for the info and add it to my DataEntry (the only important part here is the last line), I've settled logs so I know my DataEntry is receiving the data that I need.

 for(int y=0; y<NewDataSet.getPropertyCount(); y++)
{
   gfVentas = (SoapObject) NewDataSet.getProperty(y);
   if (gfVentas.getPropertyCount()==3)
   {
      if(Integer.parseInt(gfVentas.getProperty("hora").toString())==i)
      {
         vent=vent+Double.parseDouble(gfVentas.getProperty("Venta").toString());
      }

   }
   else
   {
     if(Integer.parseInt(gfVentas.getProperty("hora").toString())==i)
       {
        cob=cob+Double.parseDouble(gfVentas.getProperty("Venta").toString());
       }

   }
   dataGraf.add(new CustomDataEntry(Integer.toString(i), vent,cob));
}

Finally, I call this function from inside an onPostExecute so I know the SOAP-function is over and my data is in the DataEntry

 public void setgraph()
    {
        Set set = Set.instantiate();
        set.data(dataGraf);

        Mapping series1Data = set.mapAs("{ x: 'x', value: 'value' }");
        Mapping series2Data = set.mapAs("{ x: 'x', value: 'value2' }");

        cartesian.column(series1Data);
        cartesian.column(series2Data);
        anyChartView.setChart(cartesian);
    }

Solution

  • In the end, I just moved

    anyChartView.setChart(cartesian);
    

    to my

    onCreate()
    

    and that solved the problem, I don't really know why but I'll take it.