본문 바로가기

코틀린

안드로이드 코틀린 mpandroidchart markerview

728x90

 

 

차트에 넣을 소스

 

val marker:MyMarkerViewcontext = MyMarkerViewcontext(this@YieldActivity,R.layout.activity_my_marker_view)
pieChart!!.marker = marker

마커뷰 소스

 

class MyMarkerViewcontext(context: Context, layoutResource: Int) : MarkerView(context, layoutResource){
private lateinit var textView: TextView
var price = ""
override fun refreshContent(e: Entry?, highlight: Highlight?) {
textView = tvSimple
price = makeCommaNumber(e?.y.toString().replace(".0",""))
textView.text = "${price} "
super.refreshContent(e, highlight)
}
fun makeCommaNumber(input:String): String{
if (18 < input.length) return price
val formatter = DecimalFormat("###,###")
println(input.length)
price = formatter.format(input.toLong())

return price
}
override fun getOffset(): MPPointF {
return MPPointF(-(width / 2f), -height.toFloat() - 20f)
}
}

 

xml소스

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#999999"
tools:ignore="Overdraw">

<TextView
android:id="@+id/tvSimple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="7dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text=""
android:textSize="12sp"
android:textColor="#ffffff"
android:ellipsize="end"
android:gravity="center_vertical|center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

 

 

728x90