0

I want to connect SQLite cursor with AndroidPlot but I get error. This is my code, what would be the error?

private XYPlot mySimpleXYPlot;

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

    // initialize XYPlot reference:
    mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

    //increment Domain and Range
    mySimpleXYPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL,0.05);
    mySimpleXYPlot.setRangeStep(XYStepMode.INCREMENT_BY_VAL,0.05);

    //Open database PlotXY
    DatabaseHelper admin_PlotXY = new DatabaseHelper(this);
    SQLiteDatabase bd_PlotXY = admin_PlotXY.getWritableDatabase();

    //Cursor SQLite PlotXY
    Cursor data_PlotXY = bd_PlotXY.rawQuery(
            "select xi,yi from plot_xy", null);


    if (data_PlotXY.moveToFirst()) {

        XYSeries serie_xy = new SimpleXYSeries(data_PlotXY, SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED, "Series X=Y");
        LineAndPointFormatter seriesFormatXY = new LineAndPointFormatter(Color.rgb(127, 255, 0),0x000000,0x000000,null);
        mySimpleXYPlot.clear();
        mySimpleXYPlot.addSeries(serie_xy,seriesFormatXY);
        mySimpleXYPlot.redraw();
    }
    else{
        Toast.makeText(this, "Error en la Base de Datos plot_xy", Toast.LENGTH_SHORT).show();}
    data_PlotXY.close();
}`

the message: "Cannot resolve constructor 'SimpleXYSeries(android.databaseCursor,androidplot.xy.SimpleXYSeries.ArrayFormat,Java.lang.String)'

1 Answers1

0

There is no constructor for SimpleXYSeries that you can pass a Cursor object to. This is the signature of the constructor:

SimpleXYSeries(List<? extends Number> model, SimpleXYSeries.ArrayFormat format, String title) 

So you need to transform your Cursor into a List of Numbers or any data type that inherits from Number. Have a look at this post on how to create a List from a Cursor.

Community
  • 1
  • 1
User42
  • 970
  • 1
  • 16
  • 27