我想使用从http://www.jjoe64.com/p/graphview-library.html获取的 Graphview 库制作折线图,我的问题是我想从 JSON 中获取数据,如下所示:
[
{
"lji_invest": "Excellink Aggressive Fund",
"persen_hke1": 0,
"lnu_nilai": 3611.468,
"lji_id": "03",
"tanggal": "01/04/2013"
},
{
"lji_invest": "Excellink Aggressive Fund",
"persen_hke1": 0.001143302391160603,
"persen_hmin1": 0.001143302391160603,
"lnu_nilai": 3615.597,
"selisih": 4.129,
"lji_id": "03",
"tanggal": "02/04/2013"
},
{
"lji_invest": "Excellink Aggressive Fund",
"persen_hke1": 0.005411926673585367,
"persen_hmin1": 0.004263749527394784,
"lnu_nilai": 3631.013,
"selisih": 15.416,
"lji_id": "03",
"tanggal": "03/04/2013"
}]
我想在折线图中显示“lnu_nilai”和“tanggal”,我试过了,但我什么也没得到。这是我的源代码:
public class LineChartAsyncTask extends AsyncTask <String, String, String>{
@Override
protected void onPreExecute (){
super.onPreExecute();
Dialog=new ProgressDialog(LineChart.this);
Dialog.setMessage("Mohon Tunggu Sebentar...");
Dialog.setIndeterminate(false);
Dialog.setCancelable(true);
Dialog.show();
}
@Override
protected String doInBackground(String... params) {
String url= "http://www.sinarmaslife.co.id/E-Policy/ios/NabChart.htm?id=03&nilai=7";
try {
JSONParser jp= new JSONParser();
JSONArray ja= jp.takeJson(url);
for (int i=0; i<ja.length();i++){
JSONObject jo = ja.getJSONObject(i);
HashMap<String, String> map = new HashMap<String, String>();
if (jo.has("lnu_nilai"))
map.put("lnu_nilai", jo.get("lnu_nilai").toString());
if (jo.has("tanggal"))
map.put("tanggal", jo.get("tanggal").toString());
NabList.add(map);
}
}
catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String file_url) {
Dialog.dismiss();
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[NabList.size()] );
{
for (int i=0; i<NabList.size();i++){
HashMap MapA= new HashMap();
MapA=(HashMap) NabList.get(i);
}
}
GraphView graphView;
graphView = new LineGraphView(
this // context
, "GraphViewDemo" // heading
);
graphView.addSeries(exampleSeries); // data
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
};
}
}
我的应用程序被强制关闭,图表没有显示......我不知道我的错在哪里,我希望有人能帮我解决这个问题,谢谢