开源GraphView的使用--数据统计

本文介绍了如何利用开源库GraphView在Android中绘制数据统计曲线,特别适用于室内定位中的加速度传感器数据展示。首先从官方仓库下载.jar包,然后在Layout中添加GraphView。可以定制曲线标注、轴标签、轴范围以及图表缩放功能。此外,还能进行样式调整,如标签、背景色、字体等。
摘要由CSDN通过智能技术生成

最近做室内定位需要绘出加速度传感器输出的三个方向的加速度曲线,找到了开源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);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值