简体   繁体   English

Highcharts-数据不会加载到Android WebView的图表中

[英]Highcharts - Data won't get loaded into chart on Android WebView

The configuration has been pre-tested on Fiddler and it's all working, but somehow it stopped working when i implemented it in Android's webview. 该配置已经在Fiddler上进行了预测试,并且可以正常使用,但是当我在Android的Webview中实现该配置后,它便以某种方式停止了工作。

In my web interface class, I have a method which returns the data, and so I called the method in the HTML file in the script section as follow 在我的Web界面类中,我有一个返回数据的方法,因此我在脚本部分的HTML文件中调用了该方法,如下所示

var glucose = Android.getGlucoseData();

The debug console shows the following output of the glucose var (please don't mind the fake data) 调试控制台显示葡萄糖var的以下输出(请不要介意假数据)

[ [Date.UTC(2016, 4, 02, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 03, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 04, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 05, 19, 16, 00), 8.65999984741211],[Date.UTC(2016, 4, 06, 16, 55, 00), 9.65999984741211],[Date.UTC(2016, 4, 06, 17, 19, 00), 3.6600000858306885],[Date.UTC(2016, 4, 06, 17, 30, 00), 9.65999984741211],[Date.UTC(2016, 4, 07, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 08, 00, 00 ,00), 0.0] ] [[Date.UTC(2016,4,02,00,00,00,00],0.0],[Date.UTC(2016,4,03,00,00,00,0.0),0.0],[Date.UTC(2016, 4,04,00,00,00),0.0],[Date.UTC(2016,4,05,19,16,00),8.65999984741211],[Date.UTC(2016,4,06,16,55, 00),9.65999984741211],[Date.UTC(2016,4,06,17,19,00),3.6600000858306885],[Date.UTC(2016,4,06,17,30,00),9.65999984741211],[Date .UTC(2016,4,07,00,00,00),0.0],[日期.UTC(2016,4,08,00,00,00),0.0]]

And when I passed it into the chart 当我将其传递到图表中时

series: [{
            name: 'Glucose',
            data: glucose,
            marker: {
                enabled: true
            },
            tooltip: {
                valueSuffix: ' mmol/L'
            }
        }...

It does not render the data at all. 它根本不呈现数据。 HOWEVER if i do the following, which is essentially the same as the above, it WORKS . 但是,如果我执行以下操作(与上面的操作基本相同),它将起作用

var glucose = [ [Date.UTC(2016, 4, 02, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 03, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 04, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 05, 19, 16, 00), 8.65999984741211],[Date.UTC(2016, 4, 06, 16, 55, 00), 9.65999984741211],[Date.UTC(2016, 4, 06, 17, 19, 00), 3.6600000858306885],[Date.UTC(2016, 4, 06, 17, 30, 00), 9.65999984741211],[Date.UTC(2016, 4, 07, 00, 00 ,00), 0.0],[Date.UTC(2016, 4, 08, 00, 00 ,00), 0.0] ] var葡萄糖= [[Date.UTC(2016,4,02,00,00,00,00),0.0],[Date.UTC(2016,4,4,03,00,00,00),0.0],[Date.UTC (2016,4,04,00,00,00),0.0],[Date.UTC(2016,4,05,19,16,00),8.65999984741211],[Date.UTC(2016,4,06,16 ,55,00),9.65999984741211],[Date.UTC(2016,4,06,17,19,00),3.6600000858306885],[Date.UTC(2016,4,06,17,30,00),9.65999984741211] ,[Date.UTC(2016,4,07,00,00,00,00),0.0],[Date.UTC(2016,4,08,00,00,00,00),0.0]]

From the above, you can realise i'm just literally hardcoding the data produced by Android.getGlucoseData(); 从上面的内容,您可以意识到我只是在对Android.getGlucoseData();产生的数据进行硬编码。 into the variable. 进入变量。

May I know what did I do wrong? 我可以知道我做错了什么吗?

The issue can be caused by using Date.UTC() in JSON, which is not evaluated when you load data. 此问题可能是由于在JSON中使用Date.UTC()引起的,加载数据时不进行评估。 In other words, you cannot use functiosn in JSON. 换句话说,您不能在JSON中使用functiosn。 At the beginning, try to hardcode the timestamps (onyl for testing) and check if chart is printed or not. 在开始时,尝试对时间戳进行硬编码(用于测试的Onyl),然后检查是否已打印图表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM