2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Android】棒グラフを描画する

Posted at

概要

MPAndroidChartを用いて棒グラフを描画する。ここでは最低限の処理のみ記載。

手順

ライブラリの導入

build.gradle
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
settings.gradle
repositories {
	//(省略)
	maven { url "https://jitpack.io" }
}

レイアウト作成

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<com.github.mikephil.charting.charts.BarChart
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/chart"
	android:layout_width="match_parent"
	android:layout_height="match_parent"/>

描画処理

MainActivity.kt
val value = listOf(
	BarEntry(0f, 32f),
	BarEntry(1f, 3f),
	BarEntry(2f, 25f),
	BarEntry(3f, 47f),
	BarEntry(4f, 10f)
)

binding.chart.data = BarData(BarDataSet(value, ""))
binding.chart.invalidate()
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?