diff --git a/APED/app/build.gradle b/APED/app/build.gradle index 6ad5c46..13097f8 100644 --- a/APED/app/build.gradle +++ b/APED/app/build.gradle @@ -39,7 +39,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' implementation 'com.android.volley:volley:1.1.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'com.github.lecho:hellocharts-library:1.5.8' + implementation 'com.jjoe64:graphview:4.2.2' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/APED/app/src/main/java/com/example/aped/ui/plots/PlotFragment.java b/APED/app/src/main/java/com/example/aped/ui/plots/PlotFragment.java index ca621df..b0b6a09 100644 --- a/APED/app/src/main/java/com/example/aped/ui/plots/PlotFragment.java +++ b/APED/app/src/main/java/com/example/aped/ui/plots/PlotFragment.java @@ -12,20 +12,15 @@ import com.example.aped.MainActivity; import com.example.aped.R; import com.example.aped.communication.Communicator; import com.example.aped.utils.IXML; -import com.example.aped.utils.XMLHandler; +import com.jjoe64.graphview.GraphView; +import com.jjoe64.graphview.series.DataPoint; +import com.jjoe64.graphview.series.LineGraphSeries; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; -import java.util.Dictionary; import java.util.List; -import lecho.lib.hellocharts.model.AxisValue; -import lecho.lib.hellocharts.model.Line; -import lecho.lib.hellocharts.model.LineChartData; -import lecho.lib.hellocharts.model.PointValue; -import lecho.lib.hellocharts.view.LineChartView; public class PlotFragment extends Fragment { @@ -34,7 +29,7 @@ public class PlotFragment extends Fragment { /** List of all the devices with buffers. **/ private List bufferedDevices; /** Line Chart View that is displayed **/ - private LineChartView lineChartView; + private GraphView graphView; /** * paul @@ -52,7 +47,7 @@ public class PlotFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_plot, container, false); - this.lineChartView = view.findViewById(R.id.test_plot); + this.graphView = view.findViewById(R.id.graph); getBufferedValues(mainActivity.getDelivery(), mainActivity.getXml()); mainActivity.getConfigurationHandler().setCurrentView(R.id.nav_plots); @@ -84,16 +79,16 @@ public class PlotFragment extends Fragment { } //display data - List yAxisValues = new ArrayList(); + DataPoint[] dataPoints = new DataPoint[values.length]; for (int i = 0; i < values.length; i++){ - yAxisValues.add(values[i]); + dataPoints[i] = new DataPoint(i, values[i]); } - Line line = new Line(yAxisValues); - List lines = new ArrayList(); - lines.add(line); - LineChartData lineChartData = new LineChartData(); - lineChartData.setLines(lines); - this.lineChartView.setLineChartData(lineChartData); + LineGraphSeries lineGraphSeries = new LineGraphSeries<>(dataPoints); + this.graphView.addSeries(lineGraphSeries); + this.graphView.getViewport().setMaxX(600); + this.graphView.getViewport().setMaxY(100); + this.graphView.getViewport().setXAxisBoundsManual(true); + this.graphView.getViewport().setYAxisBoundsManual(true); } } catch (JSONException e) { Log.e("PlotFragment", "error while parsing JSON on READ BUFFER: " + e.getMessage()); diff --git a/APED/app/src/main/res/layout/fragment_plot.xml b/APED/app/src/main/res/layout/fragment_plot.xml index 8e24233..7e7f063 100644 --- a/APED/app/src/main/res/layout/fragment_plot.xml +++ b/APED/app/src/main/res/layout/fragment_plot.xml @@ -5,8 +5,8 @@ android:layout_height="match_parent" tools:context=".ui.plots.PlotFragment"> - + android:layout_height="match_parent" + android:id="@+id/graph"/> \ No newline at end of file