最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - How to get access to selected point in Android? - Stack Overflow

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论