最近做室内定位需要绘出加速度传感器输出的三个方向的加速度曲线,找到了开源https://github.com/jjoe64/GraphView-Demos,省去了要重新学MatLab *=*。
在http://www.android-graphview.org/download--getting-started.html下载.jar包。
1、GraphView的使用和普通View的使用相同。在Layout中:
<com.jjoe64.graphview.GraphView
android:layout_width="match_parent"
android:layout_height="200dip"
android:id="@+id/graph" />
2、支持三种图表:Line和Bar、Point。
<span style="white-space:pre"> </span>GraphView graph = (GraphView) findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, 1),
new DataPoint(1, 5),
new DataPoint(2, 3),
new DataPoint(3, 2),
new DataPoint(4, 6)
});
<span style="white-space:pre"> </span>graph.addSeries(series);
GraphView graph = (GraphView) rootView.findViewById(R.id.graph);
BarGraphSeries<DataPoint> series = new BarGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, -2),
new DataPoint(1, 5),
new DataPoint(2, 3),
new DataPoint(3, 2),
new DataPoint(4, 6)
});
series.setSpacing(30);
graph.addSeries(series);
<span style="white-space:pre"> </span>PointsGraphSeries<DataPoint> series3 = new PointsGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(0, 0),
new DataPoint(1, 3),
new DataPoint(2, 1),
new DataPoint(3, 0),
new DataPoint(4, 4)
});
graph.addSeries(series3);
series3.setShape(PointsGraphSeries.Shape.TRIANGLE);//设置点的形状
series3.setColor(Color.YELLOW);