使用helloCharts库实现折线图
来源:互联网 发布:邢山虎 知乎 编辑:程序博客网 时间:2024/06/05 04:36
HelloCharts在github上维护:https://github.com/lecho/hellocharts-android
1,gradle引入helloCharts开发库
dependencies{
compile'com.github.lecho:hellocharts-library:1.5.8@aar'
}
2,主布局文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<lecho.lib.hellocharts.view.LineChartView
android:id="@+id/activity_charts_line_lcv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
3,activity
package com.sonar.android.push.demo.getui.activities;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.sonar.android.push.demo.getui.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
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.view.LineChartView;
/**
* 使用HelloCharts图表开发库实现折线图
* Created by Administrator on 2016/10/26.
*/
public class ChartsActivity extends Activity{
LineChartView lineChartView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_activity_charts);
setView();
initView();
}
private void setView(){
lineChartView = (LineChartView)findViewById(R.id.activity_charts_line_lcv);
}
private void initView(){
List<PointValue> values = new ArrayList<PointValue>();
List<AxisValue> mAxisValues = new ArrayList<AxisValue>();
for (int i = 0; i < 10 ; i++) {
values.add(new PointValue(i, new Random().nextInt(5)));
mAxisValues.add(new AxisValue(i).setLabel(i+"")); //为每个对应的i设置相应的label(显示在X轴)
}
//In most cased you can call data model methods in builder-pattern-like manner.
Line line = new Line(values).setColor(Color.BLUE).setCubic(true);
List<Line> lines = new ArrayList<Line>();
lines.add(line);
LineChartData data = new LineChartData();
data.setLines(lines);
//坐标轴
Axis axisX = new Axis(); //X轴
axisX.setHasTiltedLabels(true);
axisX.setTextColor(Color.BLUE);
axisX.setName("采集时间");
axisX.setMaxLabelChars(10);
axisX.setValues(mAxisValues);
data.setAxisXBottom(axisX);
Axis axisY = new Axis(); //Y轴
axisY.setName("幅度");
axisY.setMaxLabelChars(7); //默认是3,只能看最后三个数字
data.setAxisYLeft(axisY);
lineChartView.setInteractive(true);
lineChartView.setZoomType(ZoomType.HORIZONTAL);
lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);
lineChartView.setLineChartData(data);
}
}
4,效果图
- 使用helloCharts库实现折线图
- HelloCharts图表库之折线图
- HelloCharts绘制折线图
- 折线图hellocharts-android库修改坐标、空心原点的实现
- hellocharts图表插件---折线图
- 手把手教你实现折线图之------安卓最好用的图表库hellocharts之最详细的使用介绍
- 手把手教你实现折线图之------安卓最好用的图表库hellocharts之最详细的使用介绍
- 手把手教你实现折线图之------安卓最好用的图表库hellocharts之最详细的使用介绍
- 手把手教你实现折线图之------安卓最好用的图表库hellocharts之最详细的使用介绍
- HelloCharts开源图表库(一)之折线图
- Android中对HelloCharts的修改,实现动态绘制折线图
- HelloCharts的折线图跟json数据交互
- Android 实用hellocharts实现柱状图、线状图
- hellocharts-android图表库使用详解
- 使用echarts实现动态显示折线图
- 使用MPAndroidChart开源库实现折线图
- Android 图表开源框架HelloCharts 之 柱状图、折线图、饼状图,Fragment
- Android 使用hellocharts实现初始化x轴滑动
- postgresql 中的外键
- JqueryUI-datepicker 时间段控制在30天
- MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 解决方法
- wget 连接下载超快
- 程序员代码面试指南-猫狗队列(c++)
- 使用helloCharts库实现折线图
- Android 高仿墨迹天气“我”页面
- KoaHub.JS基于Node.js开发的Lodash模块化实用程序代码
- cocos2dx 碰撞检测 总结
- Javascript面向对象编程(二):构造函数的继承
- linux(centos 64位)nodejs 安装 forever 进程守护
- 二叉查找树的基本操作
- 时间戳和标准时间转换
- Redhat 7配置yum源