2种Android图表的简单介绍+折线图、饼图的例子,字节跳动移动架构师学习笔记

这篇博客介绍了在Android中使用HelloCharts和MPAndroidChart库创建折线图和饼图的方法。通过添加依赖、设置数据和参数,展示了如何在PieChartActivity和LineChartActivity中实现图表的显示。博客提供了详细的代码示例,并提到了Android Studio的集成方法。此外,还推荐了这两个开源项目的官方资源。
摘要由CSDN通过智能技术生成

setTitle(“PieChartActivity”);

pie = (PieChart) findViewById(R.id.pie);

//②输入数据

//其中两个数字对应的分别是 X轴Y轴

list.add(new PieEntry(25,“Cola”));

list.add(new PieEntry(10, “Sprite”));

list.add(new PieEntry(13, “Fanta”));

list.add(new PieEntry(20, “Suntory”));

list.add(new PieEntry(5, “Rio”));

list.add(new PieEntry(20, “Beer”));

list.add(new PieEntry(17, “Other”));

//③定义一下饼图的颜色

ArrayList colors = new ArrayList();

colors.add(Color.RED);

colors.add(Color.GREEN);

colors.add(Color.CYAN);

colors.add(Color.MAGENTA);

colors.add(getResources().getColor(R.color.blue));

colors.add(Color.LTGRAY);

colors.add(Color.GRAY);

//⑤实例化Dataset

//list是你这条线的数据 “销售比例” 是你对这个饼的描述

PieDataSet PieDataSet = new PieDataSet(list, “销售比例”);

PieDataSet.setSliceSpace(3f); //设置饼状Item之间的间隙

PieDataSet.setColors(colors); //为DataSet中的数据匹配上颜色集(饼图Item颜色)

PieData PieData = new PieData(PieDataSet);

pie.setData(PieData);

}

}

③在AndroidManifest.xml里添加

④实现结果:

在这里插入图片描述

二、HelloCharts

支持 Android 2.2 以上;支持折线图、柱状图、饼图、气泡图、组合图;支持预览、放大缩小,滚动,部分图表支持动画;

官方项目地址:https://github.com/lecho/hellocharts-android

1.添加依赖
第一种:
Android Studio/Gradle
Maven Central/jCenter, add dependency to your build.gradle:

dependencies{

compile ‘com.github.lecho:hellocharts-library:1.5.8@aar’

}

`Project 的build.gradle文件中添加

repositories {

maven {

url “https://jitpack.io”

}

}

在 module中的build,gradle 中添加

dependencies {

compile ‘com.github.lecho:hellocharts-android:v1.5.8’

}

第二种:
【简单粗暴】本地导入依赖
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值