【问题标题】:How to get the X axis value from HighChart on android on click event如何在点击事件上从 Android 上的 HighChart 获取 X 轴值
【发布时间】:2022-01-24 01:32:27
【问题描述】:

我想要做的是单击一个 X 轴标签,然后转到另一个活动。我正在使用 highcharts 库

这就是我对图形的称呼

        val options = GraphicDataResumeUtil().getOptionData(data, productiveSelected)
        multiAxesChart.options = options
        multiAxesChart.reload()

这是我在图形类上设置 X 值的地方

fun getOptionData(
    listData: List<PoolHomeView>,
    variableSelectedCodes: List<ProductiveItemView>
): HIOptions {

    val chart = HIChart()
    chart.zoomType = "xy"
    options.chart = chart

    val title = HITitle()
    title.text = ""
    options.title = title

    val exporting = HIExporting()
    exporting.enabled = false
    options.exporting = exporting


    val listXAxis = mutableListOf<String>()

    for (i in listData.indices) {
        listXAxis.add("P " + listData[i].poolName)
    }

    val xaxis = HIXAxis()
    xaxis.categories = listXAxis.toCollection(ArrayList())
    xaxis.crosshair = HICrosshair()
    options.xAxis = ArrayList(Collections.singletonList(xaxis))

    val tooltip = HITooltip()
    tooltip.shared = true

    options.tooltip = tooltip

    return getGraphic2Axis(listData, variableSelectedCodes)
}

任何帮助或建议都会很棒,谢谢

【问题讨论】:

    标签: android kotlin highcharts


    【解决方案1】:

    很遗憾,highcharts-android 包装器不支持所需的customEvents.js 插件。

    作为替代方案,您可以考虑使用单击系列点。

    val plotoptions = HIPlotOptions()
    plotoptions.series = HISeries()
    plotoptions.series.events = HIEvents()
    plotoptions.series.point = HIPoint()
    plotoptions.series.point.events = HIEvents()
    plotoptions.series.point.events.click = HIFunction(
        HIConsumer { f: HIChartContext ->
        val t = Toast.makeText(
        this,
        "Clicked point [ " + f.getProperty("x") + ", " + f.getProperty("y") + " ]; category: " + f.getProperty(
        "category"
    ),
        Toast.LENGTH_SHORT
    )
    t.show()
    // start activity here with properties got in same way like in toast message
    }, arrayOf("x", "y", "category")
    )
    options.plotOptions = plotoptions
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多