View graph interation
GraphView graph = (GraphView)view.findViewById(R.id.graphAnnualExpense);
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] {
new DataPoint(0, 11),
new DataPoint(1, 22),
new DataPoint(2, 10),
});
//series.setTitle("Random Curve 1");
series.setColor(Color.BLUE);
series.setDrawDataPoints(true);
series.setDataPointsRadius(10);
series.setThickness(8);
graph.setTitle("Annual expenses");
graph.getGridLabelRenderer().setVerticalAxisTitle("Cost");
graph.getGridLabelRenderer().setHorizontalAxisTitle("Expenses");
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"Insurance", "Fitness", "Road Taxation" });
//staticLabelsFormatter.setVerticalLabels(new String[] {"low", "middle", "high"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
graph.addSeries(series);
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/horizontalAlignmentWithTitleBar"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:orientation="vertical"
tools:context="com.example.avitah.Fragment.AnnualExpenseReport.AnnualExpenseGraph">
<!-- TODO: Update blank fragment layout -->
<com.jjoe64.graphview.GraphView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/graphAnnualExpense" />
</FrameLayout>
Step 1
Download the library from : http://www.android-graphview.org/download-getting-started/
Step 2
in android studio in the panel "project" on the top there will be a drop down menu. click and select project
Step 3
A list of folders will appear, click on folder "app" select NEW->DIRECTORY
Step 4
Name the new directory "libs". Right click on the library just downloaded the select copy(Ctrl + C) then right click on the libs folder and select paste option (Ctrl + V)
Step 5
Once the library is in the folder libs, right click on the library and select the option "Add to library"
For more information : https://www.youtube.com/watch?v=zbTvJZX0UDk&t=213s
GraphView graph = (GraphView)view.findViewById(R.id.graphExpense);
BarGraphSeries<DataPoint> series = new BarGraphSeries<>(new DataPoint[] {
new DataPoint(0, 4),
new DataPoint(1, 1),
new DataPoint(2, 7),
new DataPoint(3, 9),
new DataPoint(4, 11),
new DataPoint(5, 2)
});
series.setValueDependentColor(new ValueDependentColor<DataPoint>() {
@Override
public int get(DataPoint data) {
return Color.rgb((int) data.getX()*255/4, (int) Math.abs(data.getY()*255/6), 100);
}
});
series.setSpacing(50);
series.setDrawValuesOnTop(true);
series.setValuesOnTopColor(Color.RED);
graph.setTitle("expenses");
graph.getGridLabelRenderer().setVerticalAxisTitle("Cost");
graph.getGridLabelRenderer().setHorizontalAxisTitle("Expenses");
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"Fuel", "Repair-servicing", "Fine" , "Parking" , "Car wash" , "Other" });
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
graph.addSeries(series);