安卓开发系列 之实现绘制折线图的方法

本文介绍使用HelloChart库在Android应用中实现折线图的方法。通过简单的代码示例展示了如何配置图表样式、添加数据点及设置交互特性,并提供布局文件示例。

在安卓开发中实现折线图的方法有MPAndroidChart、XCL-chart、achartenginee和hellochart等,这里利用hellochart进行实现,这种实现方法简单快捷,界面美观,在使用后感觉代码比较清晰,操作时比较流畅,支持饼状图、折线图、柱状图等。

需要的依赖包为:
hellocharts-library-1.5.8.jar,官方下载链接为:
https://github.com/lecho/hellocharts-android/tree/v1.5.8
其中的使用和项目代码也写的比较清晰。

第一步是将依赖包导入工程中,然后在build.gradle(app)中添加依赖,如:

implementation files('libs/hellocharts-library-1.5.8.jar')

这里的路径根据实际的依赖包路径修改,一般是放在libs文件夹中,另外注意的是在app中的build.gradle中添加依赖。

第二步是在*Activity.java文件中添加代码,主要代码有:

import lecho.lib.hellocharts.gesture.ContainerScrollType;
import lecho.lib.hellocharts.gesture.ZoomType;
import lecho.lib.hellocharts.model.Axis;
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.model.ValueShape;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.LineChartView;

public class MainActivity extends AppCompatActivity {
   
   

    public LineChartView lineChart;
    String[] date = {
   
   };//X轴的标注
    int[] score= {
   
   };//图表的数据点
    public List<PointValue> mPointValues = new ArrayList<PointValue>()
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值