added plotting of graph data

This commit is contained in:
paul-loedige 2021-01-08 01:49:04 +01:00
parent 55f4998f78
commit f4533ee427
3 changed files with 17 additions and 22 deletions

View File

@ -39,7 +39,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'com.android.volley:volley:1.1.1' implementation 'com.android.volley:volley:1.1.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' 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.+' testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

View File

@ -12,20 +12,15 @@ import com.example.aped.MainActivity;
import com.example.aped.R; import com.example.aped.R;
import com.example.aped.communication.Communicator; import com.example.aped.communication.Communicator;
import com.example.aped.utils.IXML; 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.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List; 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 { public class PlotFragment extends Fragment {
@ -34,7 +29,7 @@ public class PlotFragment extends Fragment {
/** List of all the devices with buffers. **/ /** List of all the devices with buffers. **/
private List<String> bufferedDevices; private List<String> bufferedDevices;
/** Line Chart View that is displayed **/ /** Line Chart View that is displayed **/
private LineChartView lineChartView; private GraphView graphView;
/** /**
* paul * paul
@ -52,7 +47,7 @@ public class PlotFragment extends Fragment {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_plot, container, false); 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()); getBufferedValues(mainActivity.getDelivery(), mainActivity.getXml());
mainActivity.getConfigurationHandler().setCurrentView(R.id.nav_plots); mainActivity.getConfigurationHandler().setCurrentView(R.id.nav_plots);
@ -84,16 +79,16 @@ public class PlotFragment extends Fragment {
} }
//display data //display data
List yAxisValues = new ArrayList(); DataPoint[] dataPoints = new DataPoint[values.length];
for (int i = 0; i < values.length; i++){ for (int i = 0; i < values.length; i++){
yAxisValues.add(values[i]); dataPoints[i] = new DataPoint(i, values[i]);
} }
Line line = new Line(yAxisValues); LineGraphSeries<DataPoint> lineGraphSeries = new LineGraphSeries<>(dataPoints);
List lines = new ArrayList(); this.graphView.addSeries(lineGraphSeries);
lines.add(line); this.graphView.getViewport().setMaxX(600);
LineChartData lineChartData = new LineChartData(); this.graphView.getViewport().setMaxY(100);
lineChartData.setLines(lines); this.graphView.getViewport().setXAxisBoundsManual(true);
this.lineChartView.setLineChartData(lineChartData); this.graphView.getViewport().setYAxisBoundsManual(true);
} }
} catch (JSONException e) { } catch (JSONException e) {
Log.e("PlotFragment", "error while parsing JSON on READ BUFFER: " + e.getMessage()); Log.e("PlotFragment", "error while parsing JSON on READ BUFFER: " + e.getMessage());

View File

@ -5,8 +5,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.plots.PlotFragment"> tools:context=".ui.plots.PlotFragment">
<lecho.lib.hellocharts.view.LineChartView <com.jjoe64.graphview.GraphView
android:id="@+id/test_plot"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"
android:id="@+id/graph"/>
</FrameLayout> </FrameLayout>