LoginSignup
1
0

More than 1 year has passed since last update.

【MPAndroidChart】チャートタップ時にツールチップ表示

Posted at

概要

チャートタップ時に、ツールチップ(下画像で3.0,7.0と描画されているビュー)を表示させる。

グラフの描画については、この記事を参照。

方法

ツールチップのレイアウト作成。

marker_view.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	android:id="@+id/marker_text"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:background="@color/gray"
	android:padding="8dp"
	tools:text="1.0, 2.0"/>

処理の部分。MarkerViewを使用。

MainActivity.kt
val mv = object : MarkerView(this, R.layout.marker_view) {
	override fun refreshContent(e: Entry?, highlight: Highlight?) {
		val textView: TextView = findViewById(R.id.marker_text)
		textView.text = "${e?.x}, ${e?.y}"
		super.refreshContent(e, highlight)
	}

	override fun getOffset(): MPPointF {
		return MPPointF(-width / 2f, -height - 20f)
	}
}
mv.chartView = binding.chart
binding.chart.marker = mv

参照記事

1
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
1
0