How to update data in BubbleMap ?
Hi,
First of all, thanks for your library !!!
I've a question about update of Data with a Bubble Map :
I follow this link, that's work in a BarChat, but in BubbleMap, it goes into an infinite loop in the Runnable : https://github.com/AnyChart/AnyChart-Android/wiki/Chart-data-update
Anyone ?
Thanks :)
@CharlotteJu You can update the BubbleMap chart data the same way as it is described in the article. Below is the working code:
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
final Scatter bubble = AnyChart.bubble();
List<DataEntry> data = new ArrayList<>();
data.add(new BubbleDataEntry( 184, 113, 120));
data.add(new BubbleDataEntry( 180, 94, 45));
data.add(new BubbleDataEntry( 145, 137, 123));
data.add(new BubbleDataEntry( 136, 89, 89));
data.add(new BubbleDataEntry( 180, 96, 118));
data.add(new BubbleDataEntry( 149, 113, 60));
data.add(new BubbleDataEntry( 161, 94, 87));
data.add(new BubbleDataEntry( 168, 141, 45));
data.add(new BubbleDataEntry( 173, 127, 89));
final Bubble series = bubble.bubble(data);
anyChartView.setChart(bubble);
// simulate real-time updates
final int delayMillis = 500;
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
public void run() {
// create new data List and populate it with values
List<DataEntry> data = new ArrayList<>();
data.add(new BubbleDataEntry( 184, 113, (int) (new Random().nextDouble() * 140d)));
data.add(new BubbleDataEntry( 180, 94, (int) (new Random().nextDouble() * 140d)));
data.add(new BubbleDataEntry( 145, 137, (int) (new Random().nextDouble() * 140d)));
data.add(new BubbleDataEntry( 136, 89, (int) (new Random().nextDouble() * 140d)));
data.add(new BubbleDataEntry( 180, 96, (int) (new Random().nextDouble() * 140d)));
// apply the new List to the existing chart
series.data(data);
handler.postDelayed(this, delayMillis);
}
};
handler.postDelayed(runnable, delayMillis);
The runnable is called every 500 ms.
Hi, thanks for your reply. But with this code, it goes into an infinite loop in the Runnable.
Visibly, that works with juste apply data in Set :)
@CharlotteJu
Yes, the handler every 500 ms launches the runnable. The code works correctly and it was composed this way for demonstration purposes. In real applications, you can execute the code that updates the chart data when and how you need.