First of all I need to get access the index of the selected point in chart. I set the data in series like below:
series.keys = arrayListOf("x", "y", "index")
series.data = item.trends?.mapIndexed { index, it ->
arrayOf(it.realDate, it.value, index.toString())
}
And write the code below to handle the click event:
series.point = HIPoint()
series.point.events = HIEvents()
series.point.events.click = HIFunction(
HIConsumer { f: HIChartContext ->
onPointClick.invoke()
// Access the index, x, and y properties from the point
val xValue = f.getProperty("x")
val yValue = f.getProperty("y")
val index = f.getProperty("index")
// Create a message to display
val message =
"Clicked point - Index: $index , X: $xValue, Y: $yValue"
// Show a toast with the information
val toast: Toast =
Toast.makeText(context, message, Toast.LENGTH_SHORT)
toast.show()
},
arrayOf(
"x",
"y",
"index",
) // Specify the properties you want to access
)
The toast shows the X and Y of the screen and returns null as index.
How can I have access to the index?
I need to get access the index of the selected point in chart