MPChart的饼状图使用

控件项目地址:
https://github.com/PhilJay/MPAndroidChart

效果图

这里写图片描述
这里写图片描述

使用

不过我是直接使用了MPChartLib-release.aar
下载地址:http://download.csdn.net/detail/xiehao_95/9568403

build.gradle 设置


repositories {
    
    flatDir {
    
        dirs 'libs'
    }
}

dependencies {
    
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile(name: 'MPChartLib-release', ext: 'aar')
}


  • 2.布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.github.mikephil.charting.charts.PieChart
        android:id="@+id/pieChart"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="80dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="50dp" />

</RelativeLayout>

  • 3.java代码

public class MainActivity extends AppCompatActivity {
    

    private PieChart mChart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mChart = (PieChart) findViewById(R.id.pieChart);

        int[] date = new int[]{
    1, 6, 8};
        initPieChat
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android MPChart是一款功能强大的开源图表库,用于在Android应用中显示各种类型的图表。 MPChart库支持多种类型的图表,包括折线图、柱状图、饼图、雷达图等。它可以轻松地将数据以图表的形式展示出来,帮助用户更直观地理解数据。 使用MPChart库非常简单。首先,我们需要在项目中引入MPChart库的依赖。在build.gradle文件中添加相关依赖后,就可以使用MPChart库的功能了。 接下来,我们需要创建一个图表对象,并为其设置相应的数据源。例如,如果要创建一个柱状图,我们可以使用BarChart类,并通过setData()方法设置柱状图的数据。 在设置完数据源之后,我们可以通过一些自定义的方法对图表进行个性化设置。例如,可以设置图表的颜色、字体、边框等样式,以及设置相应的动画效果。 最后,我们需要将图表对象添加到布局文件中,让其显示在界面上。我们可以通过在布局文件中添加一个ChartView视图,然后通过findViewById()方法获取该视图,并将图表对象设置给它。 使用MPChart库可以轻松地创建出漂亮、交互性强的图表。同时,MPChart库还提供了一些有用的功能,如缩放、滑动、手势操作等,方便用户在查看数据时进行细致的操作。 总的来说,Android MPChart是一款功能强大、易于使用的图表库,可以帮助开发者在Android应用中展示各种类型的图表,并提供丰富的自定义选项和交互功能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值