2016-12-30 3 views
0

私は、私はそれが正常に動作テキストビューでデシベルとビューからデータを取得するために管理しているボレーAndroidでボレーを使用してリモートサーバーデータを使用して棒グラフを作成するにはどうすればよいですか?

を使用してmysqデータベースとthis oneのような棒グラフを作成したいが、私はバーグラフ何を移入しないように、それらのデータを使用しようとすると起こります何が間違っているのか分からない。

マイJSON:

{"result":[{"id":"1","std1":"30","std2":"55","std3":"70","std4":"47","std5":"91","std6":"10","std7":"54"}]} 

そして、以下が私の全体のJavaコードである私はGithub Linkのウィキによるとhere

import android.support.v7.app.AppCompatActivity; 
    import android.os.Bundle; 
    import android.widget.TextView; 
    import android.widget.Toast; 

     import com.android.volley.Request; 
     import com.android.volley.RequestQueue; 
     import com.android.volley.Response; 
     import com.android.volley.VolleyError; 
     import com.android.volley.toolbox.JsonObjectRequest; 
     import com.android.volley.toolbox.Volley; 

     import org.json.JSONArray; 
     import org.json.JSONException; 
     import org.json.JSONObject; 

     import java.util.ArrayList; 
     import com.github.mikephil.charting.charts.BarChart; 
     import com.github.mikephil.charting.data.BarData; 
     import com.github.mikephil.charting.data.BarDataSet; 
     import com.github.mikephil.charting.data.BarEntry; 
     import com.github.mikephil.charting.utils.ColorTemplate; 

    public class MainActivity extends AppCompatActivity { 
    TextView textView; 
    RequestQueue requestQueue; 

    BarChart chart ; 
    ArrayList<BarEntry> BARENTRY ; 
    ArrayList<String> BarEntryLabels ; 
    BarDataSet Bardataset ; 
    BarData BARDATA ; 

     @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    textView=(TextView)findViewById(R.id.viewData); 


    chart = (BarChart) findViewById(R.id.chart1); 

    BARENTRY = new ArrayList<>(); 

    BarEntryLabels = new ArrayList<String>(); 

    AddValuesToBarEntryLabels(); 

    Bardataset = new BarDataSet(BARENTRY, "Projects"); 

    BARDATA = new BarData(BarEntryLabels, Bardataset); 

    Bardataset.setColors(ColorTemplate.COLORFUL_COLORS); 

    chart.setData(BARDATA); 

    chart.animateY(3000); 
    AddValuesToBARENTRY(); 

     requestQueue = Volley.newRequestQueue(this); 
     JsonObjectRequest jsonObjectRequest 
    =new JsonObjectRequest(Request.Method.POST, http://**/**/barGraphData2.php", new Response.Listener<JSONObject>() { 
     @Override 
     public void onResponse(JSONObject response) { 
      try { 
       JSONArray jsonArray= response.getJSONArray("result"); 
      for(int i=0;i<jsonArray.length();i++){ 
      JSONObject result= jsonArray.getJSONObject(i); 
       String std1= result.getString("std1"); 
       String std2= result.getString("std2"); 
       String std3= result.getString("std3"); 
       String std4= result.getString("std4"); 
       String std5= result.getString("std5"); 
       String std6= result.getString("std6"); 
       String std7= result.getString("std7"); 


       // View data in text few 
       textView.setText(
          "bar 1 -->"+std1+"\n" 
         +"bar 2 -->"+std2+"\n" 
         +"bar 3 -->"+std3+"\n" 
         +"bar 4 -->"+std4+"\n" 
         +"bar 5 -->"+std5+"\n" 
         +"bar 6 -->"+std6+"\n" 
         +"bar 7 -->"+std7+"\n" 
           ); 
       //call method to use information in barGraph 
     AddValuesToBARENTRY (std1, std2, std3, std4, std5, std6); 

      } 

      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } 
    }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        Toast.makeText(getApplicationContext(),"there is error bro",Toast.LENGTH_LONG).show(); 
       } 
      } 
    ) ; 
requestQueue.add(jsonObjectRequest); 
} 


public void AddValuesToBARENTRY(String std1,String std2,String std3,String std4,String std5,String std6){ 
    BARENTRY.add(new BarEntry(Float.parseFloat(std1), 0)); 
    BARENTRY.add(new BarEntry(Float.parseFloat(std2), 1)); 
    BARENTRY.add(new BarEntry(Float.parseFloat(std3), 2)); 
    BARENTRY.add(new BarEntry(Float.parseFloat(std4), 3)); 
    BARENTRY.add(new BarEntry(Float.parseFloat(std5), 4)); 
    BARENTRY.add(new BarEntry(Float.parseFloat(std6), 5)); 

} 

public void AddValuesToBarEntryLabels(){ 

    BarEntryLabels.add("January"); 
    BarEntryLabels.add("February"); 
    BarEntryLabels.add("March"); 
    BarEntryLabels.add("April"); 
    BarEntryLabels.add("May"); 
    BarEntryLabels.add("June"); 

} 
} 
+0

を試してみてください。空の値を設定しますか? –

答えて

0

からバーグラフのコンセプトを踏襲し、あなたは棒グラフをリフレッシュする必要がありますデータが設定された後

はAddValuesToBARENTRY()

//call method to use information in barGraph 
AddValuesToBARENTRY (std1, std2, std3, std4, std5, std6); 
// refresh the bar chart 
chart.invalidate(); 
関連する問題