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