Android开源框架——图表MPAndroidChart

开源官网:https://github.com/PhilJay/MPAndroidChart

Android开源框架——图表MPAndroidChart

MPAndroidChart是一个功能强大,简单易用的图表开源库,支持API8及以上版本。它能实现Android与IOS跨平台开发。


特点

  • 8种不同的图表类型
  • 支持缩放功能
  • 支持拖动与平移
  • 组合图(线性,条形,散点,k线)
  • 双(单)轴
  • 可自定义坐标轴(x轴,y轴)
  • 突出显示值 (可定制弹出视图)
  • 将图表以JPG,PNG或txt形式保存到SD卡中
  • 预定义颜色模板
  • 图例(自动产生,可定制)
  • 构建动画效果(x轴,y轴都可以)
  • 限制线(提供额外的信息)
  • 完全可定制化(画笔,字体,图例,颜色,背景,手势,虚线)
  • 线性表或条形表中可以缩放或者滚动达到30000条数据
  • Gradle支持
  • 绘制的数据可以直接来自Realm.io移动数据库中


配置

Gradle

  • Add the following to your build.gradle:
repositories {
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
}

Maven

  • Add the following to your pom.xml:
<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.PhilJay</groupId>
    <artifactId>MPAndroidChart</artifactId>
    <version>v2.2.5</version>
</dependency>

图表类型

  1. LineChart (with legend, simple design)
    这里写图片描述

    LineChart (with legend, simple design)
    这里写图片描述


    LineChart (cubic lines)
    这里写图片描述


    LineChart (gradient fill)
    这里写图片描述


  2. Combined-Chart (bar- and linechart in this case)
    这里写图片描述


  3. BarChart (with legend, simple design)
    这里写图片描述


    BarChart (grouped DataSets)
    这里写图片描述


  4. Horizontal-BarChart
    这里写图片描述

  5. PieChart (with selection, …)
    这里写图片描述

  6. ScatterChart (with squares, triangles, circles, … and more)
    这里写图片描述

  7. CandleStickChart (for financial data)
    这里写图片描述


  8. BubbleChart (area covered by bubbles indicates the value)
    这里写图片描述


  9. RadarChart (spider web chart)
    这里写图片描述




Demo

package com.android.chart;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.utils.ColorTemplate;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        List<BarEntry> entries = new ArrayList<>();
        entries.add(new BarEntry(4f,0));
        entries.add(new BarEntry(8f,1));
        entries.add(new BarEntry(6f,2));
        entries.add(new BarEntry(12f,3));
        entries.add(new BarEntry(18f,4));
        entries.add(new BarEntry(9f,5));
        BarDataSet dataSet = new BarDataSet(entries,"# of Calls");
        dataSet.setColors(ColorTemplate.COLORFUL_COLORS);

        List<String> labels = new ArrayList<>();
        labels.add("January");
        labels.add("February");
        labels.add("March");
        labels.add("April");
        labels.add("May");
        labels.add("June");

        BarData data = new BarData(labels,dataSet);
        BarChart barChart = new BarChart(this);
        barChart.setData(data);
        barChart.setDescription("# of times Alice called Bob");


        setContentView(barChart);

    }
}



这里写图片描述






参考:
【1】http://www.jianshu.com/p/791b7eba2dd4
【2】 http://blog.csdn.net/shineflowers/article/details/44701645
【3】http://code.tutsplus.com/tutorials/add-charts-to-your-android-app-using-mpandroidchart–cms-23335

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值