MPAndroidChart
MPAndroidChart copied to clipboard
Clicked view/coordinate information on pie chart
val params = halfChart.layoutParams as ConstraintLayout.LayoutParams
params.setMargins(0, 0, 0, -offset)
halfChart.layoutParams = params
halfChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener {
override fun onValueSelected(e: Entry?, h: Highlight?) {
halfChart.highlightValues(null)
val label = e?.data.toString()
val percent = (e?.y ?: 0f) / halfChart.data.yValueSum * 100
val formattedPercent =
String.format("%.2f", percent) // Yüzdeyi iki ondalıklı hale getir
val balloon = createBalloon(this@AboutAppActivity) {
setWidthRatio(0.25f)
setHeight(BalloonSizeSpec.WRAP)
setText("$label: $formattedPercent%")
setTextColorResource(R.color.white)
setTextSize(5f)
setIconDrawableResource(R.drawable.ic_about_app)
setArrowSize(10)
setArrowPosition(0.5f)
setPadding(12)
setCornerRadius(8f)
setBackgroundColorResource(R.color.primary)
setLifecycleOwner(this@AboutAppActivity)
}
**balloon.showAlignTop(halfChart,0,0)**.
}
override fun onNothingSelected() {
TODO("Not yet implemented")
}
})}
Hi, How can I get the X,Y coordinates of the area I clicked on in the pie chart? Or how can I get the clicked area view in the in the pie chart? I want to show a balloon at these coordinates/views that I click on.