This is an example which creates a custom line graph. The coordinates are retrieved from a text file in the assets folder.
There are custom attributes provided for the custom line graph.
- The attributes
x_max
andy_max
are mandatory, which denote the length of x-axis and y-axis. Otherwise,GraphException
will be thrown. - Other attributes are not mandatory, but it would be good if we can provide stuff like
x_unit_spacing
andy_unit_spacing
. All custom attributes can be found atres/values/attrs.xml
- By default, all sides padding for the graph is zero.
- The project shows an activity which retrieves all the points using
PointManager
and then passes them to theLineGraph
. - Graph can be created both dynamically and using Android XML.
- Problems due to screen rotations is also handled.
Creating a custom line graph,
- Using Android XML,
<org.custom.graph.line.LineGraph
xmlns:custom="http://schemas.android.com/apk/res/org.custom.graph"
android:id="@+id/lineGraph"
android:layout_width="300dp"
android:layout_height="100dp"
android:paddingLeft="10dp"
custom:label_color="#ff0000"
custom:x_label="runs"
custom:x_max="100"
custom:x_unit_spacing="10"
custom:y_max="400"
custom:y_unit_spacing="10" />
- Dynamically,
LineGraph lineGraph = new LineGraph(this);
lineGraph.setXMax(300);
lineGraph.setYMax(100);
lineGraph.setXUnitSpacing(10);
lineGraph.setYUnitSpacing(10);
lineGraph2.setLineColor(Color.RED);
layout.addView(lineGraph);
Dynamic creation of Custom Line Graph.- Done!- Providing more options for customization.
- Asynchronous loading of points within the graph.
- Making this Custom Line Graph a standalone library.