AnyChart-Android icon indicating copy to clipboard operation
AnyChart-Android copied to clipboard

How to update chart with new data from web service? (already checked other posts)

Open Fdde11 opened this issue 5 years ago • 1 comments

Hi! 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 i = 0; i <=24; i++)
{
                    double vent=0,cob=0;
                    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);
    }

Fdde11 avatar Apr 30 '20 18:04 Fdde11

@Fdde11 There's no need to clean the DataEntry. You can simply override it with new data and apply it to the existing chart. For details, check this comment

Shestac92 avatar May 02 '20 10:05 Shestac92