尝试使用highcharts将数据点注入iOS webView

时间:2015-05-31 12:30:30

标签: javascript ios swift highcharts uiwebview

在将Android应用程序移植到iOS时,我们遇到了障碍: 我们设置了一个UIwebView来运行HighCharts(它可以使用他们提供的示例),但我们无法弄清楚如何将变量传递给Javascript以显示实时更改。 我们尝试做的与Android相当的是:

webView.loadUrl("javascript:" + "point = " + "[Date.UTC("
                    + mYear + "," + mMonth + "," + mDay + "," + hr
                    + "," + min + "," + sec + "),"
                    + value+ "];");

或其他例子:

webView.loadUrl("javascript:" + "var curve_name = " + "'Illuminance';" +
                    "var unit_of_meas = " + "'lx';" +
                    "var x_axis_title = " + "'Date';" +
                    "var y_axis_title = " + "'Illuminance (lx)';" +
                    "var plot_title = " + "'Illuminance data';" +
                    "var plot_subtitle = " + "'';")

1 个答案:

答案 0 :(得分:0)

UIWebView有一个名为stringByEvaluatingJavaScriptFromString的方法,可用于运行脚本。我认为您也可以使用它来传递和初始化您喜欢的任何变量。