HoloGraphLibrary三方图表框架
HoloGraphLibrary 说实话 我觉得很坑我下面说一下 HoloGraphLibrary的简单使用。从GitHub到自己的项目 。
先说一下东西:
GitHub官网地址:https://github.com/Androguide/HoloGraphLibrary
开发工具:android studio 2.2.3(2.3已出)
测试手机:夜神模拟器,金立
1、下载:
从GitHub官网clone项目到本地或者直接下载到本地:
下载下来解压后的文件夹如下:
我们要用到的就是HoloGraphLibrary文件夹
2、集成到我们的android studio
1、打开我们的android studio
File - ->New - ->Import Module
2、找到我们HoloGraphLibrary文件夹 finish
3、修改版本信息
对照着build.gradle(Moudle.app) 修改我们右边的版本信息。
4、syn now 或者rebuild 一下工程 集成就ok了
OK,我们集成讲完了 我们现在来说一下使用。
效果图:
LineGraph:
Activity:
package com.wentong.administrator.holographdemo.activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.echo.holographlibrary.Line;
import com.echo.holographlibrary.LineGraph;
import com.echo.holographlibrary.LinePoint;
import com.wentong.administrator.holographdemo.R;
/**
* Created by Administrator on 2017/3/16.
*/
public class LineGraphActivity extends AppCompatActivity{
LineGraph lineGraph ;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_linegraph);
initView() ;
}
private void initView() {
lineGraph = (LineGraph) findViewById(R.id.act_lg_lineGraph) ;
Line l = new Line();
LinePoint p = new LinePoint();
p.setX(0);
p.setY(5);
l.addPoint(p);
p = new LinePoint();
p.setX(3);
p.setY(8);
l.addPoint(p);
p = new LinePoint();
p.setX(6);
p.setY(4);
l.addPoint(p);
p = new LinePoint();
p.setX(9);
p.setY(7);
l.addPoint(p);
p = new LinePoint();
p.setX(12);
p.setY(2);
l.addPoint(p);
l.setColor(Color.parseColor("#FFBB33"));
lineGraph.addLine(l);
lineGraph.setRangeY(0, 10);
lineGraph.setLineToFill(0);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.echo.holographlibrary.LineGraph
android:id="@+id/act_lg_lineGraph"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
BarGraph:
Activity:
package com.wentong.administrator.holographdemo.activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.echo.holographlibrary.Bar;
import com.echo.holographlibrary.BarGraph;
import com.wentong.administrator.holographdemo.R;
import java.util.ArrayList;
/**
* Created by Administrator on 2017/3/16.
*/
public class BarGraphActivity extends AppCompatActivity{
BarGraph barGraph ;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bargraph);
initView() ;
}
private void initView() {
barGraph = (BarGraph) findViewById(R.id.act_bg_barGraph) ;
ArrayList<Bar> points = new ArrayList<Bar>();
Bar d = new Bar();
d.setColor(Color.parseColor("#99CC00"));
d.setName("Test1");
d.setValue(10);
Bar d2 = new Bar();
d2.setColor(Color.parseColor("#FFBB33"));
d2.setName("Test2");
d2.setValue(20);
points.add(d);
points.add(d2);
barGraph.setBars(points);
barGraph.setUnit("$");
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.echo.holographlibrary.BarGraph
android:id="@+id/act_bg_barGraph"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
PieGraph:
Activity:
package com.wentong.administrator.holographdemo.activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.echo.holographlibrary.PieGraph;
import com.echo.holographlibrary.PieSlice;
import com.wentong.administrator.holographdemo.R;
/**
* Created by Administrator on 2017/3/16.
*/
public class PieGraphActivity extends AppCompatActivity{
PieGraph pieGraph ;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_piegraph);
initView() ;
}
private void initView() {
pieGraph = (PieGraph) findViewById(R.id.act_pg_pieGraph) ;
PieSlice slice = new PieSlice();
slice.setColor(Color.parseColor("#99CC00"));
slice.setValue(2);
pieGraph.addSlice(slice);
slice = new PieSlice();
slice.setColor(Color.parseColor("#FFBB33"));
slice.setValue(3);
pieGraph.addSlice(slice);
slice = new PieSlice();
slice.setColor(Color.parseColor("#AA66CC"));
slice.setValue(8);
pieGraph.addSlice(slice);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.echo.holographlibrary.PieGraph
android:id="@+id/act_pg_pieGraph"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
OK!
这篇没有注解,因为我写的实在是太low。后面有好看的我会加上注解。