Anychart使用函数作为参数创建图形

问题描述

我具有用于创建AnyChart图形的此功能。我想为像这样的不同图形提供很多功能,并将它们显示在不同的MaterialDialogs中。

        private fun createChart(): Cartesian {
            val cartesian: Cartesian = AnyChart.cartesian(
            (...)
            return cartesian
        }

为此任务,我做了一个常规功能,将使用特定的视图ID和用于创建图形的特定功能进行调用

private fun showDialog(layoutId : Int,chartId : Int,function: (Chart)) {

        val dialog = MaterialDialog(requireContext())
            .customView(layoutId)
            .cornerRadius(5.5f)

        val chartView: AnyChartView = dialog.findViewById(chartId)
        APIlib.getInstance().setActiveAnyChartView(chartView)
        chartView.setDebug(true)

        chartView.setChart(function) // <------ The problem is here
        //chartView.setChart(createChart() works fine 
        dialog.show()
    }

我将在某些视图的onClick侦听器上调用此函数,并指定要显示的图表和要使用的绘制函数

private fun showWeatherDialog() {
        showDialog(R.layout.activity_graph_test,R.id.any_chart_view,createChart())
}

如果我使用普通的函数调用,则会正常绘制图形,但是当我调用函数参数时,图形将不起作用

   chartView.setChart(function) // <------ The problem is here
   //chartView.setChart(createChart() works fine

Anychart的错误:

E / AnyChart:未捕获的ReferenceError:未定义cartesian43

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)