-
Notifications
You must be signed in to change notification settings - Fork 131
Open
Description
我需要实现类似 RecyclerView 中的 scrollToPosition 功能,能够滚动到指定位置并选中或者模拟点击。
目前,我通过修改更新 AAChartModel 的 scrollablePlotArea 中的 scrollPositionX 来显示指定位置的区域,如下所示:
private fun configureChartModel(position: Int): AAChartModel {
// 提取日期(用于x轴)和步数(用于y轴)
val dates = stepsList.map { SimpleDateFormat("MM-dd", Locale.getDefault()).format(it.date) }
val stepCounts = stepsList.map { it.stepCount }
val minWidth = 45 * stepsList.size
val aaChartModel = AAChartModel()
.chartType(AAChartType.Column)
.backgroundColor("#ffffff")
.dataLabelsEnabled(true)
.legendEnabled(false)
.touchEventEnabled(true) // 开启触摸监听
.clickEventEnabled(true) // 开启点击监听
.categories(dates.toTypedArray())
.series(
arrayOf(
AASeriesElement()
.color("#2891FA40") // 柱子颜色 注意最后的40才是透明度25%
.states(
AAStates()
.hover(
AAHover()
.color("#2891FA")
)
) // 高亮颜色
.name("") // 图例的名字 即使设置 legendEnabled=false 隐藏图例也需要设置name为空,不然toolsTip会出现默认名字 Series 1
.data(stepCounts.toTypedArray())
)
)
.scrollablePlotArea(
AAScrollablePlotArea()
.minWidth(minWidth) // 需要完整展示绘图区域的最小宽度 https://github.com/AAChartModel/AAChartKit/issues/1602
.scrollPositionX(position)
.opacity(1f)
)
val option = aaChartModel.aa_toAAOptions()
val yAxis = AAYAxis().gridLineDashStyle(AAChartLineDashStyleType.Dash.value).title(AAAxisTitle().text(""))
option.yAxis = yAxis
binding.aaChart.aa_drawChartWithChartOptions(option)
return aaChartModel
}
fun updateChartPosition() {
binding.apply {
aaChartModel = configureChartModel(8)
aaChart.aa_refreshChartWithChartModel(aaChartModel)
}
}
我想知道是否有更合适的方式去实现scrollToPosition
并且我现在没有实现滚动出来指定区域后对应的item高亮的效果,有什么方法可以模拟点击吗?
谢谢
Metadata
Metadata
Assignees
Labels
No labels