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

推荐订阅源

爱范儿
爱范儿
Security Latest
Security Latest
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Cybersecurity and Infrastructure Security Agency CISA
Cloudbric
Cloudbric
T
Threat Research - Cisco Blogs
大猫的无限游戏
大猫的无限游戏
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
C
Cisco Blogs
V
Vulnerabilities – Threatpost
S
Security Archives - TechRepublic
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
J
Java Code Geeks
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Know Your Adversary
Know Your Adversary
博客园 - 叶小钗
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy International News Feed
P
Palo Alto Networks Blog
博客园_首页
V
V2EX
WordPress大学
WordPress大学
Schneier on Security
Schneier on Security
月光博客
月光博客
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
TaoSecurity Blog
TaoSecurity Blog
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
The Cloudflare Blog
罗磊的独立博客
美团技术团队
N
News | PayPal Newsroom
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Last Week in AI
Last Week in AI
K
Kaspersky official blog
Google Online Security Blog
Google Online Security Blog
S
SegmentFault 最新的问题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tailwind CSS Blog

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