家庭版记账本app开发之关于(数据库查找出数据)圆饼图的生成
这次完成的主要的怎样从数据库中调出数据。之后通过相关的数据,生成想要的圆饼图。以方便用户更加直观的看见关于账本的基本情况。
在圆饼图生成中用到了一些外部资源
具体的import如下:
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import java.util.ArrayList;
这些是用到的外部的相关资源:
通过这些就可以很简单的是用圆饼图的生成:
具体的代码分析如下:
一、饼状图上字体的设置
// entry label styling
pieChart.setDrawEntryLabels(true);//设置是否绘制Label
pieChart.setEntryLabelColor(Color.RED);//设置绘制Label的颜色
pieChart.setEntryLabelTextSize(20f);//设置绘制Label的字体大小
二、饼图颜色
colors.add(Color.rgb(205, 205, 205));
colors.add(Color.rgb(114, 188, 223));
pieDataSet.setColors(colors); pieDataSet.setSliceSpace(0f);//设置选中的Tab离两边的距离
pieDataSet.setSelectionShift(5f);//设置选中的tab的多出来的
PieData pieData = new PieData();
pieData.setDataSet(pieDataSet); 三、各个饼状图所占比例数字的设置
pieData.setValueFormatter(new PercentFormatter());//设置%
pieData.setValueTextSize(20f);
pieData.setValueTextColor(Color.YELLOW);
四、pieChart.setUsePercentValues(true);//设置value是否用显示百分数,默认为false
。这些是用到的主要知识点:
具体的代码只有一个.java文件还有一个.xml文件
java文件如下:
public class ThePieChare3 extends AppCompatActivity {
private PieChart pieChart;
private Context context;
private Intent intent2;
private String username;
private int zhichujine,shourujine;
private DBOpenMessage dbOpenMessage;
private TextView shourutxt,zhichutxt; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.piechare3);
pieChart = (PieChart) findViewById(R.id.wenpie3); context=this;
intent2=getIntent();
username=intent2.getStringExtra("username");
dbOpenMessage=new DBOpenMessage(ThePieChare3.this,"db_wen2",null,1);
getMessage1(username); shourutxt=(TextView)findViewById(R.id.wentext32);
zhichutxt=(TextView)findViewById(R.id.wentext31); shourutxt.setText(Integer.toString(shourujine));
zhichutxt.setText(Integer.toString(zhichujine)); pieChart.setUsePercentValues(true);
pieChart.setDescription("所有金额支出收入总情况");
pieChart.setDescriptionTextSize(20); pieChart.setExtraOffsets(5, 5, 5, 5); pieChart.setDrawCenterText(true);
pieChart.setCenterTextColor(Color.RED);
pieChart.setCenterTextSize(15); pieChart.setDrawHoleEnabled(true);
pieChart.setHoleColor(Color.WHITE);
pieChart.setHoleRadius(40f); pieChart.setTransparentCircleColor(Color.BLACK);
pieChart.setTransparentCircleAlpha(100);
pieChart.setTransparentCircleRadius(40f); // enable rotation of the chart by touch
pieChart.setRotationEnabled(true);
pieChart.setRotationAngle(10); pieChart.setHighlightPerTapEnabled(true); Legend l = pieChart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART_CENTER); l.setForm(Legend.LegendForm.LINE);
l.setYEntrySpace(0f);
l.setYOffset(0f); // entry label styling
pieChart.setDrawEntryLabels(true);
pieChart.setEntryLabelColor(Color.RED);
pieChart.setEntryLabelTextSize(20f); // pieChart.setOnChartValueSelectedListener(this);
pieChart.animateY(3400, Easing.EasingOption.EaseInQuad);
ArrayList<PieEntry> pieEntries = new ArrayList<PieEntry>(); pieEntries.add(new PieEntry(zhichujine, "总支出金额"));
pieEntries.add(new PieEntry(shourujine, "总收入金额"));
String centerText ;
if(shourujine>zhichujine)
{
centerText = "整体为正资产:\n+¥" + (shourujine-zhichujine);
}
else if(shourujine<zhichujine)
{
centerText = "整体为负资产:\n-¥" + (zhichujine-shourujine);
}
else
{
centerText = "整体资产为零";
} pieChart.setCenterText(centerText);
PieDataSet pieDataSet = new PieDataSet(pieEntries, "");
ArrayList<Integer> colors = new ArrayList<Integer>(); colors.add(Color.rgb(205, 205, 205));
colors.add(Color.rgb(114, 188, 223));
pieDataSet.setColors(colors); pieDataSet.setSliceSpace(0f);
pieDataSet.setSelectionShift(5f);
PieData pieData = new PieData();
pieData.setDataSet(pieDataSet); pieData.setValueFormatter(new PercentFormatter());
pieData.setValueTextSize(20f);
pieData.setValueTextColor(Color.YELLOW); pieChart.setData(pieData);
// undo all highlights
pieChart.highlightValues(null);
pieChart.invalidate();
}
private void getMessage1(String username) {
Cursor cursor=dbOpenMessage.getAllCostData(username);
if(cursor!=null){
while(cursor.moveToNext()){
Message message2=new Message();
message2.userkind=cursor.getString(cursor.getColumnIndex("userkind"));
message2.usermoney=cursor.getString(cursor.getColumnIndex("usermoney"));
message2.userchoice=cursor.getString(cursor.getColumnIndex("userchoice"));
if(message2.userchoice.equals("支出"))
{
zhichujine+=Integer.parseInt(message2.usermoney);
}
else if(message2.userchoice.equals("收入"))
{
shourujine+=Integer.parseInt(message2.usermoney);
} }
}
}
}
与之对应的.xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ThePieChare1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="支出各项占比圆饼图"
android:layout_marginTop="10dp"
android:textSize="30dp"
android:textColor="@color/lanse"
android:layout_marginBottom="20dp"
android:gravity="center_horizontal"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:layout_marginLeft="70dp"
android:textSize="20dp"
android:text="食品总支出:"/>
<TextView
android:id="@+id/wentext11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:text=""/>
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:layout_marginLeft="70dp"
android:textSize="20dp"
android:text="衣物总支出:"/>
<TextView
android:id="@+id/wentext12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:text=""/>
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:layout_marginLeft="70dp"
android:textSize="20dp"
android:text="出行总支出:"/>
<TextView
android:id="@+id/wentext13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:text=""/>
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:layout_marginLeft="70dp"
android:textSize="20dp"
android:text="其他总支出:"/>
<TextView
android:id="@+id/wentext14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
android:layout_marginLeft="10dp"
android:textSize="20dp"
android:text=""/>
</LinearLayout> <com.github.mikephil.charting.charts.PieChart
android:id="@+id/wenpie1"
android:layout_width="match_parent"
android:layout_height="320dp"
android:layout_gravity="center_vertical">
</com.github.mikephil.charting.charts.PieChart>
</LinearLayout>
这样就完成了关于图表生成的步骤;
具体对应的实验结果如下:
点击第一个生成第一个图表:
图表是动态生成的:(可以满足旋转生成)
家庭版记账本app开发之关于(数据库查找出数据)圆饼图的生成的更多相关文章
- 家庭版记账本app开发完成
经过这几天关于android的相关学习,对于家庭版记账本app以及开发结束. 实现的功能为:用户的注册.登录.添加支出账单.添加收入账单.显示所有的该用户的账单情况(收入和支出).生产图表(直观的显示 ...
- 家庭版记账本app开发进度相关界面的规划
总的app界面包括四个页面,页面可以来回滑动.设计的时候就和微信的四个页面类似. 由于没有找到合适的图标进行替换,在此仍应用微信对应的四个图标. 总的四个页面是: 1.增加收入或者支出的小账单.当点击 ...
- 家庭版记账本app开发进度。开发到现在整个app只剩下关于图表的设计了,具体功能如下
首先说一下自己的功能: 实现了用户的登录和注册.添加收入记账和添加支出记账.粗略显示每条账单基本情况.通过点击每条账单来显示具体的情况, 之后就是退出当前用户的操作. 具体的页面情况如下: 这就是整个 ...
- 简单记账本APP开发一
在对Android的一些基础的知识有了一定了解,以及对于AndroidStudio的如何使用有了 一定的熟悉后,决定做一个简单的记账本APP 开发流程 1.记账本的页面 2.可以添加新的账目 (一)页 ...
- 家庭版记账本app进度之关于listview显示账单,并为其添加点击事件
这个主要学习是关于listview的学习. 怎样去自定义adapter,以及使用.自己创建文件,还有就是为listview的每一个子控件添加点击事件. 在整个过程中收获到的知识点如下: 一.对于数据库 ...
- 简单记账本APP开发二
今天主要是进行了适配器的编写,数据库的创建以及对完善了业务逻辑,简单的APP到此已经通过测试可以使用.
- 家庭版记账本app进度之关于android界面布局的相关学习
1.线性布局(linearlayout)是一种让视图水平或垂直线性排列的布局线性布局使用<LinearLayout>标签进行配置对应代码中的类是android.widget.LinearL ...
- 家庭版记账本app进度之对于按钮的点击事件以及线性布局以及(alertdialog)等相关内容的应用测试
通过线性布局,制作出连个按钮还有文本输入框以及嘴上放的标题文本进行信息的相关显示,完后最后的信息的输入,之后在屏幕的的下方进行显示 当点击第一个按钮的时候,在下方就会简单的出现你自己刚刚输入的相关信息 ...
- 家庭版记账本app之常用控件的使用方法
现在先介绍在android开发的时候会用的相关的控件,做一个基本的了解方便我们之后对其进行相关具体的操作.下面是相应额详细情况: TextView android:layout_width 和 and ...
随机推荐
- Simulink仿真入门到精通(三) Simulink信号
3.1 Simulink信号概述 所谓信号,表示一种随着时间而变化的量,在时间轴上的采样时刻都对应有数值. 信号在Simulink中是相当重要的组成部分,有线(line)表示,在模型中穿针引线地将各模 ...
- go中处理各种请求方式以及处理接口请求参数
话不多说直接上代码,解读内容全部在代码中 1.处理请求方式 package main import ( "fmt" "io/ioutil" "net/ ...
- Django中update和save()同时作用
数据更新操作,对单条记录,可以使用save或者是update两种方式. save() 默认保存后会看到sql语句中更新了所有字段,而save的值是之前获取时候的字段值,是缓存下来的,并不一定最新,可能 ...
- JAVAEE学习day04方法的定义和重载
1.方法定义的格式 方法就是完成特定功能的代码块 修饰符 返回值类型 方法名(参数类型 参数名1, 参数类型 参数名2...){ 方法体; return 返回值; } 修饰符: 初学者只需记住publ ...
- C++ Dll中导出一个类
//定义一个头文件,创建MyObject.h的头文件 并打印如下代码 #ifndef _MY_OBJECT_H #define _MY_OBJECT_H #ifndef MYDLL_EXPORTS # ...
- 【Weiss】【第03章】练习3.22、3.23、3.24:无代码题,栈的思考题
[练习3.22] a.提出支持栈的Push和Pop操作以及第三种操作FindMin的数据结构,其中FindMin 返回该数据结构的最小元素,所有操作在最坏情况下的运行时间都是O(1). b.证明,如果 ...
- void指针和数组指针之间的转换
由于void* 可以被任何指针赋值,所以以void*作为函数参数可以使得接口更容易接受不同类型的参数,不过需要注意的时,实际操作时还需要利用强制类型转换,将指针转换为原类型,否则在内存上会有问题. 一 ...
- Fiddler4 手机抓包
1.要对计算机Fiddler进行配置,允许远程计算机连接. 2.保证手机电脑在同一局域网中. 3.手机上设置代理服务器.以华为手机为例,设置-->WLAN-->找到并长按目前所连接的WiF ...
- Kubernetes实战总结 - 系统初始化
设置系统主机名以及Host文件的相互解析 hostnamectl set-hostname k8s-master01 cat >> /etc/hosts <<EOF 192.1 ...
- ABP实践(4)-abp前端vue框架之简单商品增删改查(帮助刚入门的新手快速了解怎么才能加入自己的功能并运行起来)
提示:如有不明白的地方请先查看前3篇ABP实践系列的文章 1,下载及启动abp项目前后端分离(netcore+vue) 2,修改abp数据库为mysql 3,商品系列api接口(本文主要依赖在这个商品 ...