惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

Lan小站-嗯,不错! - 安卓

android stadio 一直在下载download fastutil-7.2.0.jar - Lan小站-嗯,不错! Android为属性组件动画无效 - Lan小站-嗯,不错! JavaScript调用Android方法,显示Echarts - Lan小站-嗯,不错! 安卓实时获取数据并刷新图表 - Lan小站-嗯,不错! Gson解析百度实时热榜Json数据 - Lan小站-嗯,不错! 按照第一行代码使用ToolBar报错。 - Lan小站-嗯,不错! Android webView打开网页 - Lan小站-嗯,不错! Android VideoView播放视频 - Lan小站-嗯,不错! 安卓MPAndroidChart绘制多层级的堆叠条形图 - Lan小站-嗯,不错!
安卓MPAndroidChart绘制水平柱状图 - Lan小站-嗯,不错!
Lan · 2020-10-10 · via Lan小站-嗯,不错! - 安卓

image.png

这个和垂直柱状图一模一样,只不过把控件名换了一下从barchart换成了HorizontalBarChart

XML文件

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="水平柱状图" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:orientation="vertical">

    <com.github.mikephil.charting.charts.HorizontalBarChart
        android:id="@+id/horizontalBarChart"
        android:layout_width="match_parent"
        android:layout_height="150dp" />
</LinearLayout>

MainActivity

//初始化水平柱状图
HorizontalBarChart horizontalBarChart = findViewById(R.id.horizontalBarChart);
initBarChart(horizontalBarChart);
horizontalBarChart.setData(setBarData());
barChart.invalidate();

public BarChart initBarChart(BarChart barChart) {
    barChart.setDrawBarShadow(false); // 设置每条柱子的阴影不显示
    barChart.setDrawValueAboveBar(true); // 设置每条柱子的数值显示
    barChart.setPinchZoom(false);
    XAxis xAxis = barChart.getXAxis(); // 获取柱状图的x轴
    YAxis yAxisLeft = barChart.getAxisLeft(); // 获取柱状图左侧的y轴
    YAxis yAxisRight = barChart.getAxisRight(); // 获取柱状图右侧的y轴
    setAxis(xAxis, yAxisLeft, yAxisRight); //调用方法设置柱状图的轴线
    return barChart;
}

public BarData setBarData() {
    List<BarEntry> entries = new ArrayList<>(); //定义一个数据容器
    //生成随机数数据
    for (int i = 0; i <= 12; i++) {
        entries.add(new BarEntry(i, new Random().nextInt(300)));
    }
    BarDataSet barDataSet = new BarDataSet(entries, "测试数据");
    BarData barData = new BarData(barDataSet);
    return barData; //返回可用于柱状图的数据
}

文章参考:https://blog.csdn.net/weixin_43344890/article/details/103008320