在HighChart android中添加数组数据

Add array data in HighChart android

本文关键字:数组 数据 添加 HighChart android      更新时间:2023-09-26

我在将数组/数据从android/java代码加载到highchart/html代码时遇到了一些问题。当我将数据放入静态时,它运行良好:

series: [{
        name:'Fruit',
        data: [{name:"Test 1",y:10},
               {name:"Test 2",y:20},
               {name:"Test 3",y:30},]}]

但是当我尝试从我的java代码中添加它时:

//graph_webview_test is my webview and add the GraphWebInterface() as javascript
graph_webview_test.addJavascriptInterface(new GraphWebInterface(), "Android");

//a method of GraphWebInterface
@JavascriptInterface
    public String getStringTickets(){
        String temp="";
        for(int x=0;x<graphTicketArrayList.size();x++){
            temp= temp+"{name:"+"'""+graphTicketArrayList.get(x).getLabel()+"'""+",y:"+graphTicketArrayList.get(x).getTotal()+"},";
        }
        return temp;
    }

//i tried to print the result(Sample_graph.html)
console.log(Android.getStringTickets());
result:  "{name:"Test 1",y:10},{name:"Test 2",y:20},{name:"Test 3",y:30}",

and call the method to load data.
series: [{
         name:'Fruit',
         data: [Android.getStringTickets()]
                    }]

但是highChart显示0个数据和一个标签(切片)

在高图中加载数组的最佳方法是什么。

谢谢各位,

只想分享我们的解决方案。我的错误是我没有将字符串从android/java转换为对象。所以我们添加。

var temp=eval('['+Android.getStringTickets()+']');

以及在添加数据时:

series: [{
          ame:'Crime',
          data: temp }]