Search code examples
androidfirebasefirebase-realtime-databaseandroidplotreal-time-data

Can I take a values from google firebase to my XYPlot?


Hi I am new to android and I am developing an app to display a temperature data that I get from my firebase database. I am following the following tutorial to draw the graph https://www.youtube.com/watch?v=wEFkzQY_wWI . But I am not finding many tutorials on how to connect a database to XYplot. Please help me

public class MainActivity extends AppCompatActivity {

private XYPlot plot;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    plot = (XYPlot) findViewById(R.id.plot);

    XYSeries s1 = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "series 1", 1,3,6,4,2,6,9);

    plot.addSeries(s1, new LineAndPointFormatter(Color.GREEN, Color.GREEN, null, null));

    PanZoom.attach(plot);
}}

Solution

  • Androidplot (or any other plotting library of which I'm aware) does not provide utilities for mapping your firebase database to an XYSeries.

    Writing your own adapter is the best approach and requires only a trivial amount of code. Probably on the order of 10 lines. One simplistic approach would be to implement the XYSeries interface and have it wrap your firebase database. How exactly you map indexes in the series to your database depends on the type of database and how you've organized the data.