Я хочу показать маркер при нажатии значения на графике. Я попробовал все в документации, но маркер не отображается. Любые идеи? Вот мой код
Я думаю, что даже эта функция не работает, потому что печать "MARKERVIEW PRUEBA" не показывает
public class YourMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, layoutResource) {
lateinit private var tvContent:TextView
lateinit private var mOffset:MPPointF
init {
println("MARKERVIEW PRUEBA")
tvContent = findViewById(R.id.tvContent) as TextView
mOffset = MPPointF(-(getWidth() / 2).toFloat(), -getHeight().toFloat())
}
// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
override fun refreshContent(e:Entry, highlight:Highlight) {
tvContent.setText("" + e.y)
println("PRUEBA MARKERVIEW")
// this will perform necessary layouting
super.refreshContent(e, highlight)
}
override fun getOffset():MPPointF {
if (mOffset != null){
// center the marker horizontally and vertically
mOffset = MPPointF(-(getWidth() / 2).toFloat(), -getHeight().toFloat())
} else {
println("MOFFSET NULL")
}
return mOffset
}
}
И моя диаграмма:
fun armarChartPeso() {
var entries: ArrayList<Entry> = arrayListOf()
for (i in 0..pesos!!.size - 1) {
println("--------------------------------------------------------")
//https://github.com/PhilJay/MPAndroidChart/issues/789
//DEBE ESTAR FECHA ASCENDENTE
val reference_timestamp = pesos!![0]!!.fechaRegistro!!.time
val xNew = pesos!![i]!!.fechaRegistro!!.time - reference_timestamp
println("EL FLOAT DEL PUNTO ES")
println(xNew.toFloat())
println(xNew.toLong())
println("EL REFTIMESTAMP DEL PUNTO ES")
println(reference_timestamp)
// tipo de letra
val tf = ResourcesCompat.getFont(this.context!!, R.font.montserrat_regular)
val xAxisFormatter = FooFormatter(reference_timestamp, xNew.toLong())
val xAxis = chart.xAxis
xAxis.setValueFormatter(xAxisFormatter)
xAxis.setTypeface(tf)
xAxis.textSize = 12f
xAxis.setLabelCount(6, true)
xAxis.setCenterAxisLabels(true)
val yAxis = chart.axisLeft
yAxis.setTypeface(tf)
yAxis.textSize = 12f
yAxis.setLabelCount(5, true)
yAxis.setCenterAxisLabels(true)
val punto = Entry(xNew.toFloat(), pesos!![i]!!.peso.toFloat())
entries.add(punto)
}
val dataSet = LineDataSet(entries, "Label") // add entries to dataset\
dataSet.setColor(Color.parseColor("#ffc300"))
dataSet.setDrawValues(false)
dataSet.lineWidth = 2.5f
dataSet.setCircleColor(Color.parseColor("#ffc300"))
val lineData = LineData(dataSet)
chart.legend.isEnabled = false
chart.description.isEnabled = false
chart.setDrawGridBackground(false)
chart.xAxis.setDrawGridLines(false)
chart.axisLeft.setDrawGridLines(false)
chart.axisRight.setDrawGridLines(false)
chart.xAxis.setDrawAxisLine(true)
chart.axisRight.setDrawAxisLine(false)
chart.axisRight.setDrawLabels(false)
chart.setExtraBottomOffset(6f)
chart.setExtraRightOffset(25f)
chart.setHighlightPerTapEnabled(true)
chart.setTouchEnabled(true)
val marker = YourMarkerView(this.activity,R.layout.tvcontent)
chart.setMarker(marker)
chart.isDragEnabled = false
chart.xAxis.position = XAxis.XAxisPosition.BOTTOM
chart.setDrawBorders(false)
chart.animateX(300)
chart.setData(lineData)
chart.invalidate()
}
И мой телеконтент xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="@drawable/fondo_textview_gris" >
<TextView
android:id="@+id/tvContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=""
android:textSize="12dp"
android:textColor="#404040"
android:fontFamily="@font/montserrat_regular"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>