0
从我的android/java代码加载数组/数据到highchart/html代码有点麻烦。它工作正常,当我会把数据静态:在HighChart中添加数组数据android
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的数据和标签(slice)
在highchart中加载数组的最佳方法是什么?
谢谢你们,
你应该有你的数据集后,后面的逗号?通常情况下,JS数据结构的最后一项没有逗号 – 2014-09-04 03:26:20
嗨雷蒙,你是指这个系列:['name':'Fruit', data:[{name:“Test 1”,y:10}, {name:“Test 2”,y:20}, {name:“Test 3”,y:30},]}] 我试过这段代码,它正常运行,所以我做了一个String具有此格式的数组,但不显示图形。 – chkm8 2014-09-04 03:31:26
你可以发布你用来生成这个'系列的java代码:[[name:'Fruit', data:[Android.getStringTickets()] }] – 2014-09-04 03:35:36