android-plot bar chart from mysql database











up vote
1
down vote

favorite












I need a solution for this problem. Currently I had follow this video https://www.youtube.com/watch?v=EBGdWPBdfPo&t=104s. I need to plot using my own data. I already save the data from mysql to php but I do not know how to display the data in my android studio. Please help me.
This is my php code:






<?php

require_once 'connect.php';

//checking if any error occured while connecting
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

//creating a query
$stmt = $conn->prepare("SELECT AVG(rb_fd),AVG(rb_check_in),AVG(rb_check_out),AVG(rb_room),AVG(rb_staff),AVG(rb_navigation),AVG(rb_fs),AVG(rb_decor),AVG(rb_facilities),AVG(rb_wifi) FROM rating;");

//executing the query
$stmt->execute();

//binding result to the query
$stmt->bind_result($rb_fd,$rb_check_in,$rb_check_out,$rb_room,$rb_staff,$rb_navigation,$rb_fs,$rb_decor,$rb_facilities,$rb_wifi);

$rating = array();

//traversing throung all the result
while($stmt->fetch()){
$temp = array();
$temp['FD'] = $rb_fd;
$temp['CI'] = $rb_check_in;
$temp['CO'] = $rb_check_out;
$temp['R'] = $rb_room;
$temp['S'] = $rb_staff;
$temp['N'] = $rb_navigation;
$temp['FS'] = $rb_fs;
$temp['D'] = $rb_decor;
$temp['F'] = $rb_facilities;
$temp['W'] = $rb_wifi;
array_push($rating, $temp);
}

//displaying the result in json format
echo json_encode($rating);

?>





This is the output when I check at Postman:






[
{
"FD": 2.5,
"CI": 2.5,
"CO": 2.6666666666666665,
"R": 2.5,
"S": 3,
"N": 3.3333333333333335,
"FS": 3,
"D": 2,
"F": 3.5,
"W": 3.6666666666666665
}
]





This is my code in android studio.






package com.example.user.hotelsuriamalaqaapp;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.Rating;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

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.StringRequest;
import com.android.volley.toolbox.Volley;
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class AdminViewRating extends AppCompatActivity {

private BarChart barChart;
private BarData barData;
private ListView rate;

List<Rate2> ratingList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_view_rating);

//This is code for bar chart
barChart = (BarChart) findViewById(R.id.barchart);
barData = new BarData(getXvalues(), getBarValues());
barData.setValueTextColor(Color.WHITE);
barChart.setData(barData);
barChart.setBackgroundColor(Color.WHITE);
barChart.getXAxis().setTextColor(Color.BLACK);
barChart.setDescription("Rating");

barChart.setGridBackgroundColor(Color.DKGRAY);
barChart.animateXY(3000, 3000);
barChart.invalidate();

rate=findViewById(R.id.rate3);

ratingList=new ArrayList<>();
}

private ArrayList<BarDataSet> getBarValues() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, constant.URL_KIRA,
new Response.Listener<String>() {
ArrayList<BarDataSet> barDataSets;
ArrayList<BarEntry> barEntries = new ArrayList<>();
BarDataSet barDataSet = new BarDataSet(barEntries, "Rates");
barDataSets = new ArrayList<>();

try {
//converting the string to json array object
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray=jsonObject.getJSONArray("rating");

//traversing through all the object
for (int i = 0; i < jsonArray.length(); i++) {

//getting product object from json array
JSONObject object = jsonArray.getJSONObject(i);

ratingList.add(new Rate2(
object.getString("FD"),
object.getString("CI"),
object.getString("CO"),
object.getString("R"),
object.getString("S"),
object.getString("N"),
object.getString("FS"),
object.getString("D"),
object.getString("F"),
object.getString("W")
));
//barEntries.add(new BarEntry(rate,i);
}

barDataSet.setColor(Color.RED);
barDataSets.add(barDataSet);


} catch (JSONException e) {
e.printStackTrace();
}
return barDataSets;
}




//This is coding for x axis
private ArrayList<String> getXvalues(){
ArrayList<String> xvalues = new ArrayList<>();
xvalues.add("FD");
xvalues.add("CI");
xvalues.add("CO");
xvalues.add("R");
xvalues.add("S");
xvalues.add("N");
xvalues.add("FS");
xvalues.add("D");
xvalues.add("F");
xvalues.add("W");

return xvalues;
}


}












share|improve this question
























  • you have gotten data to PHP. but PHP is running on your server. you need to present it in a format (e.g. JSON) so that you can fetch it from your android application via a http call, then you can display it.
    – JoSSte
    Nov 19 at 6:42















up vote
1
down vote

favorite












I need a solution for this problem. Currently I had follow this video https://www.youtube.com/watch?v=EBGdWPBdfPo&t=104s. I need to plot using my own data. I already save the data from mysql to php but I do not know how to display the data in my android studio. Please help me.
This is my php code:






<?php

require_once 'connect.php';

//checking if any error occured while connecting
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

//creating a query
$stmt = $conn->prepare("SELECT AVG(rb_fd),AVG(rb_check_in),AVG(rb_check_out),AVG(rb_room),AVG(rb_staff),AVG(rb_navigation),AVG(rb_fs),AVG(rb_decor),AVG(rb_facilities),AVG(rb_wifi) FROM rating;");

//executing the query
$stmt->execute();

//binding result to the query
$stmt->bind_result($rb_fd,$rb_check_in,$rb_check_out,$rb_room,$rb_staff,$rb_navigation,$rb_fs,$rb_decor,$rb_facilities,$rb_wifi);

$rating = array();

//traversing throung all the result
while($stmt->fetch()){
$temp = array();
$temp['FD'] = $rb_fd;
$temp['CI'] = $rb_check_in;
$temp['CO'] = $rb_check_out;
$temp['R'] = $rb_room;
$temp['S'] = $rb_staff;
$temp['N'] = $rb_navigation;
$temp['FS'] = $rb_fs;
$temp['D'] = $rb_decor;
$temp['F'] = $rb_facilities;
$temp['W'] = $rb_wifi;
array_push($rating, $temp);
}

//displaying the result in json format
echo json_encode($rating);

?>





This is the output when I check at Postman:






[
{
"FD": 2.5,
"CI": 2.5,
"CO": 2.6666666666666665,
"R": 2.5,
"S": 3,
"N": 3.3333333333333335,
"FS": 3,
"D": 2,
"F": 3.5,
"W": 3.6666666666666665
}
]





This is my code in android studio.






package com.example.user.hotelsuriamalaqaapp;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.Rating;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

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.StringRequest;
import com.android.volley.toolbox.Volley;
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class AdminViewRating extends AppCompatActivity {

private BarChart barChart;
private BarData barData;
private ListView rate;

List<Rate2> ratingList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_view_rating);

//This is code for bar chart
barChart = (BarChart) findViewById(R.id.barchart);
barData = new BarData(getXvalues(), getBarValues());
barData.setValueTextColor(Color.WHITE);
barChart.setData(barData);
barChart.setBackgroundColor(Color.WHITE);
barChart.getXAxis().setTextColor(Color.BLACK);
barChart.setDescription("Rating");

barChart.setGridBackgroundColor(Color.DKGRAY);
barChart.animateXY(3000, 3000);
barChart.invalidate();

rate=findViewById(R.id.rate3);

ratingList=new ArrayList<>();
}

private ArrayList<BarDataSet> getBarValues() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, constant.URL_KIRA,
new Response.Listener<String>() {
ArrayList<BarDataSet> barDataSets;
ArrayList<BarEntry> barEntries = new ArrayList<>();
BarDataSet barDataSet = new BarDataSet(barEntries, "Rates");
barDataSets = new ArrayList<>();

try {
//converting the string to json array object
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray=jsonObject.getJSONArray("rating");

//traversing through all the object
for (int i = 0; i < jsonArray.length(); i++) {

//getting product object from json array
JSONObject object = jsonArray.getJSONObject(i);

ratingList.add(new Rate2(
object.getString("FD"),
object.getString("CI"),
object.getString("CO"),
object.getString("R"),
object.getString("S"),
object.getString("N"),
object.getString("FS"),
object.getString("D"),
object.getString("F"),
object.getString("W")
));
//barEntries.add(new BarEntry(rate,i);
}

barDataSet.setColor(Color.RED);
barDataSets.add(barDataSet);


} catch (JSONException e) {
e.printStackTrace();
}
return barDataSets;
}




//This is coding for x axis
private ArrayList<String> getXvalues(){
ArrayList<String> xvalues = new ArrayList<>();
xvalues.add("FD");
xvalues.add("CI");
xvalues.add("CO");
xvalues.add("R");
xvalues.add("S");
xvalues.add("N");
xvalues.add("FS");
xvalues.add("D");
xvalues.add("F");
xvalues.add("W");

return xvalues;
}


}












share|improve this question
























  • you have gotten data to PHP. but PHP is running on your server. you need to present it in a format (e.g. JSON) so that you can fetch it from your android application via a http call, then you can display it.
    – JoSSte
    Nov 19 at 6:42













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I need a solution for this problem. Currently I had follow this video https://www.youtube.com/watch?v=EBGdWPBdfPo&t=104s. I need to plot using my own data. I already save the data from mysql to php but I do not know how to display the data in my android studio. Please help me.
This is my php code:






<?php

require_once 'connect.php';

//checking if any error occured while connecting
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

//creating a query
$stmt = $conn->prepare("SELECT AVG(rb_fd),AVG(rb_check_in),AVG(rb_check_out),AVG(rb_room),AVG(rb_staff),AVG(rb_navigation),AVG(rb_fs),AVG(rb_decor),AVG(rb_facilities),AVG(rb_wifi) FROM rating;");

//executing the query
$stmt->execute();

//binding result to the query
$stmt->bind_result($rb_fd,$rb_check_in,$rb_check_out,$rb_room,$rb_staff,$rb_navigation,$rb_fs,$rb_decor,$rb_facilities,$rb_wifi);

$rating = array();

//traversing throung all the result
while($stmt->fetch()){
$temp = array();
$temp['FD'] = $rb_fd;
$temp['CI'] = $rb_check_in;
$temp['CO'] = $rb_check_out;
$temp['R'] = $rb_room;
$temp['S'] = $rb_staff;
$temp['N'] = $rb_navigation;
$temp['FS'] = $rb_fs;
$temp['D'] = $rb_decor;
$temp['F'] = $rb_facilities;
$temp['W'] = $rb_wifi;
array_push($rating, $temp);
}

//displaying the result in json format
echo json_encode($rating);

?>





This is the output when I check at Postman:






[
{
"FD": 2.5,
"CI": 2.5,
"CO": 2.6666666666666665,
"R": 2.5,
"S": 3,
"N": 3.3333333333333335,
"FS": 3,
"D": 2,
"F": 3.5,
"W": 3.6666666666666665
}
]





This is my code in android studio.






package com.example.user.hotelsuriamalaqaapp;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.Rating;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

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.StringRequest;
import com.android.volley.toolbox.Volley;
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class AdminViewRating extends AppCompatActivity {

private BarChart barChart;
private BarData barData;
private ListView rate;

List<Rate2> ratingList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_view_rating);

//This is code for bar chart
barChart = (BarChart) findViewById(R.id.barchart);
barData = new BarData(getXvalues(), getBarValues());
barData.setValueTextColor(Color.WHITE);
barChart.setData(barData);
barChart.setBackgroundColor(Color.WHITE);
barChart.getXAxis().setTextColor(Color.BLACK);
barChart.setDescription("Rating");

barChart.setGridBackgroundColor(Color.DKGRAY);
barChart.animateXY(3000, 3000);
barChart.invalidate();

rate=findViewById(R.id.rate3);

ratingList=new ArrayList<>();
}

private ArrayList<BarDataSet> getBarValues() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, constant.URL_KIRA,
new Response.Listener<String>() {
ArrayList<BarDataSet> barDataSets;
ArrayList<BarEntry> barEntries = new ArrayList<>();
BarDataSet barDataSet = new BarDataSet(barEntries, "Rates");
barDataSets = new ArrayList<>();

try {
//converting the string to json array object
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray=jsonObject.getJSONArray("rating");

//traversing through all the object
for (int i = 0; i < jsonArray.length(); i++) {

//getting product object from json array
JSONObject object = jsonArray.getJSONObject(i);

ratingList.add(new Rate2(
object.getString("FD"),
object.getString("CI"),
object.getString("CO"),
object.getString("R"),
object.getString("S"),
object.getString("N"),
object.getString("FS"),
object.getString("D"),
object.getString("F"),
object.getString("W")
));
//barEntries.add(new BarEntry(rate,i);
}

barDataSet.setColor(Color.RED);
barDataSets.add(barDataSet);


} catch (JSONException e) {
e.printStackTrace();
}
return barDataSets;
}




//This is coding for x axis
private ArrayList<String> getXvalues(){
ArrayList<String> xvalues = new ArrayList<>();
xvalues.add("FD");
xvalues.add("CI");
xvalues.add("CO");
xvalues.add("R");
xvalues.add("S");
xvalues.add("N");
xvalues.add("FS");
xvalues.add("D");
xvalues.add("F");
xvalues.add("W");

return xvalues;
}


}












share|improve this question















I need a solution for this problem. Currently I had follow this video https://www.youtube.com/watch?v=EBGdWPBdfPo&t=104s. I need to plot using my own data. I already save the data from mysql to php but I do not know how to display the data in my android studio. Please help me.
This is my php code:






<?php

require_once 'connect.php';

//checking if any error occured while connecting
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

//creating a query
$stmt = $conn->prepare("SELECT AVG(rb_fd),AVG(rb_check_in),AVG(rb_check_out),AVG(rb_room),AVG(rb_staff),AVG(rb_navigation),AVG(rb_fs),AVG(rb_decor),AVG(rb_facilities),AVG(rb_wifi) FROM rating;");

//executing the query
$stmt->execute();

//binding result to the query
$stmt->bind_result($rb_fd,$rb_check_in,$rb_check_out,$rb_room,$rb_staff,$rb_navigation,$rb_fs,$rb_decor,$rb_facilities,$rb_wifi);

$rating = array();

//traversing throung all the result
while($stmt->fetch()){
$temp = array();
$temp['FD'] = $rb_fd;
$temp['CI'] = $rb_check_in;
$temp['CO'] = $rb_check_out;
$temp['R'] = $rb_room;
$temp['S'] = $rb_staff;
$temp['N'] = $rb_navigation;
$temp['FS'] = $rb_fs;
$temp['D'] = $rb_decor;
$temp['F'] = $rb_facilities;
$temp['W'] = $rb_wifi;
array_push($rating, $temp);
}

//displaying the result in json format
echo json_encode($rating);

?>





This is the output when I check at Postman:






[
{
"FD": 2.5,
"CI": 2.5,
"CO": 2.6666666666666665,
"R": 2.5,
"S": 3,
"N": 3.3333333333333335,
"FS": 3,
"D": 2,
"F": 3.5,
"W": 3.6666666666666665
}
]





This is my code in android studio.






package com.example.user.hotelsuriamalaqaapp;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.Rating;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

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.StringRequest;
import com.android.volley.toolbox.Volley;
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class AdminViewRating extends AppCompatActivity {

private BarChart barChart;
private BarData barData;
private ListView rate;

List<Rate2> ratingList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_view_rating);

//This is code for bar chart
barChart = (BarChart) findViewById(R.id.barchart);
barData = new BarData(getXvalues(), getBarValues());
barData.setValueTextColor(Color.WHITE);
barChart.setData(barData);
barChart.setBackgroundColor(Color.WHITE);
barChart.getXAxis().setTextColor(Color.BLACK);
barChart.setDescription("Rating");

barChart.setGridBackgroundColor(Color.DKGRAY);
barChart.animateXY(3000, 3000);
barChart.invalidate();

rate=findViewById(R.id.rate3);

ratingList=new ArrayList<>();
}

private ArrayList<BarDataSet> getBarValues() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, constant.URL_KIRA,
new Response.Listener<String>() {
ArrayList<BarDataSet> barDataSets;
ArrayList<BarEntry> barEntries = new ArrayList<>();
BarDataSet barDataSet = new BarDataSet(barEntries, "Rates");
barDataSets = new ArrayList<>();

try {
//converting the string to json array object
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray=jsonObject.getJSONArray("rating");

//traversing through all the object
for (int i = 0; i < jsonArray.length(); i++) {

//getting product object from json array
JSONObject object = jsonArray.getJSONObject(i);

ratingList.add(new Rate2(
object.getString("FD"),
object.getString("CI"),
object.getString("CO"),
object.getString("R"),
object.getString("S"),
object.getString("N"),
object.getString("FS"),
object.getString("D"),
object.getString("F"),
object.getString("W")
));
//barEntries.add(new BarEntry(rate,i);
}

barDataSet.setColor(Color.RED);
barDataSets.add(barDataSet);


} catch (JSONException e) {
e.printStackTrace();
}
return barDataSets;
}




//This is coding for x axis
private ArrayList<String> getXvalues(){
ArrayList<String> xvalues = new ArrayList<>();
xvalues.add("FD");
xvalues.add("CI");
xvalues.add("CO");
xvalues.add("R");
xvalues.add("S");
xvalues.add("N");
xvalues.add("FS");
xvalues.add("D");
xvalues.add("F");
xvalues.add("W");

return xvalues;
}


}








<?php

require_once 'connect.php';

//checking if any error occured while connecting
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

//creating a query
$stmt = $conn->prepare("SELECT AVG(rb_fd),AVG(rb_check_in),AVG(rb_check_out),AVG(rb_room),AVG(rb_staff),AVG(rb_navigation),AVG(rb_fs),AVG(rb_decor),AVG(rb_facilities),AVG(rb_wifi) FROM rating;");

//executing the query
$stmt->execute();

//binding result to the query
$stmt->bind_result($rb_fd,$rb_check_in,$rb_check_out,$rb_room,$rb_staff,$rb_navigation,$rb_fs,$rb_decor,$rb_facilities,$rb_wifi);

$rating = array();

//traversing throung all the result
while($stmt->fetch()){
$temp = array();
$temp['FD'] = $rb_fd;
$temp['CI'] = $rb_check_in;
$temp['CO'] = $rb_check_out;
$temp['R'] = $rb_room;
$temp['S'] = $rb_staff;
$temp['N'] = $rb_navigation;
$temp['FS'] = $rb_fs;
$temp['D'] = $rb_decor;
$temp['F'] = $rb_facilities;
$temp['W'] = $rb_wifi;
array_push($rating, $temp);
}

//displaying the result in json format
echo json_encode($rating);

?>





<?php

require_once 'connect.php';

//checking if any error occured while connecting
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

//creating a query
$stmt = $conn->prepare("SELECT AVG(rb_fd),AVG(rb_check_in),AVG(rb_check_out),AVG(rb_room),AVG(rb_staff),AVG(rb_navigation),AVG(rb_fs),AVG(rb_decor),AVG(rb_facilities),AVG(rb_wifi) FROM rating;");

//executing the query
$stmt->execute();

//binding result to the query
$stmt->bind_result($rb_fd,$rb_check_in,$rb_check_out,$rb_room,$rb_staff,$rb_navigation,$rb_fs,$rb_decor,$rb_facilities,$rb_wifi);

$rating = array();

//traversing throung all the result
while($stmt->fetch()){
$temp = array();
$temp['FD'] = $rb_fd;
$temp['CI'] = $rb_check_in;
$temp['CO'] = $rb_check_out;
$temp['R'] = $rb_room;
$temp['S'] = $rb_staff;
$temp['N'] = $rb_navigation;
$temp['FS'] = $rb_fs;
$temp['D'] = $rb_decor;
$temp['F'] = $rb_facilities;
$temp['W'] = $rb_wifi;
array_push($rating, $temp);
}

//displaying the result in json format
echo json_encode($rating);

?>





[
{
"FD": 2.5,
"CI": 2.5,
"CO": 2.6666666666666665,
"R": 2.5,
"S": 3,
"N": 3.3333333333333335,
"FS": 3,
"D": 2,
"F": 3.5,
"W": 3.6666666666666665
}
]





[
{
"FD": 2.5,
"CI": 2.5,
"CO": 2.6666666666666665,
"R": 2.5,
"S": 3,
"N": 3.3333333333333335,
"FS": 3,
"D": 2,
"F": 3.5,
"W": 3.6666666666666665
}
]





package com.example.user.hotelsuriamalaqaapp;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.Rating;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

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.StringRequest;
import com.android.volley.toolbox.Volley;
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class AdminViewRating extends AppCompatActivity {

private BarChart barChart;
private BarData barData;
private ListView rate;

List<Rate2> ratingList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_view_rating);

//This is code for bar chart
barChart = (BarChart) findViewById(R.id.barchart);
barData = new BarData(getXvalues(), getBarValues());
barData.setValueTextColor(Color.WHITE);
barChart.setData(barData);
barChart.setBackgroundColor(Color.WHITE);
barChart.getXAxis().setTextColor(Color.BLACK);
barChart.setDescription("Rating");

barChart.setGridBackgroundColor(Color.DKGRAY);
barChart.animateXY(3000, 3000);
barChart.invalidate();

rate=findViewById(R.id.rate3);

ratingList=new ArrayList<>();
}

private ArrayList<BarDataSet> getBarValues() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, constant.URL_KIRA,
new Response.Listener<String>() {
ArrayList<BarDataSet> barDataSets;
ArrayList<BarEntry> barEntries = new ArrayList<>();
BarDataSet barDataSet = new BarDataSet(barEntries, "Rates");
barDataSets = new ArrayList<>();

try {
//converting the string to json array object
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray=jsonObject.getJSONArray("rating");

//traversing through all the object
for (int i = 0; i < jsonArray.length(); i++) {

//getting product object from json array
JSONObject object = jsonArray.getJSONObject(i);

ratingList.add(new Rate2(
object.getString("FD"),
object.getString("CI"),
object.getString("CO"),
object.getString("R"),
object.getString("S"),
object.getString("N"),
object.getString("FS"),
object.getString("D"),
object.getString("F"),
object.getString("W")
));
//barEntries.add(new BarEntry(rate,i);
}

barDataSet.setColor(Color.RED);
barDataSets.add(barDataSet);


} catch (JSONException e) {
e.printStackTrace();
}
return barDataSets;
}




//This is coding for x axis
private ArrayList<String> getXvalues(){
ArrayList<String> xvalues = new ArrayList<>();
xvalues.add("FD");
xvalues.add("CI");
xvalues.add("CO");
xvalues.add("R");
xvalues.add("S");
xvalues.add("N");
xvalues.add("FS");
xvalues.add("D");
xvalues.add("F");
xvalues.add("W");

return xvalues;
}


}





package com.example.user.hotelsuriamalaqaapp;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.Rating;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

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.StringRequest;
import com.android.volley.toolbox.Volley;
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class AdminViewRating extends AppCompatActivity {

private BarChart barChart;
private BarData barData;
private ListView rate;

List<Rate2> ratingList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_view_rating);

//This is code for bar chart
barChart = (BarChart) findViewById(R.id.barchart);
barData = new BarData(getXvalues(), getBarValues());
barData.setValueTextColor(Color.WHITE);
barChart.setData(barData);
barChart.setBackgroundColor(Color.WHITE);
barChart.getXAxis().setTextColor(Color.BLACK);
barChart.setDescription("Rating");

barChart.setGridBackgroundColor(Color.DKGRAY);
barChart.animateXY(3000, 3000);
barChart.invalidate();

rate=findViewById(R.id.rate3);

ratingList=new ArrayList<>();
}

private ArrayList<BarDataSet> getBarValues() {
StringRequest stringRequest = new StringRequest(Request.Method.GET, constant.URL_KIRA,
new Response.Listener<String>() {
ArrayList<BarDataSet> barDataSets;
ArrayList<BarEntry> barEntries = new ArrayList<>();
BarDataSet barDataSet = new BarDataSet(barEntries, "Rates");
barDataSets = new ArrayList<>();

try {
//converting the string to json array object
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray=jsonObject.getJSONArray("rating");

//traversing through all the object
for (int i = 0; i < jsonArray.length(); i++) {

//getting product object from json array
JSONObject object = jsonArray.getJSONObject(i);

ratingList.add(new Rate2(
object.getString("FD"),
object.getString("CI"),
object.getString("CO"),
object.getString("R"),
object.getString("S"),
object.getString("N"),
object.getString("FS"),
object.getString("D"),
object.getString("F"),
object.getString("W")
));
//barEntries.add(new BarEntry(rate,i);
}

barDataSet.setColor(Color.RED);
barDataSets.add(barDataSet);


} catch (JSONException e) {
e.printStackTrace();
}
return barDataSets;
}




//This is coding for x axis
private ArrayList<String> getXvalues(){
ArrayList<String> xvalues = new ArrayList<>();
xvalues.add("FD");
xvalues.add("CI");
xvalues.add("CO");
xvalues.add("R");
xvalues.add("S");
xvalues.add("N");
xvalues.add("FS");
xvalues.add("D");
xvalues.add("F");
xvalues.add("W");

return xvalues;
}


}






php android mysql android-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 7:00

























asked Nov 19 at 6:39









noney

62




62












  • you have gotten data to PHP. but PHP is running on your server. you need to present it in a format (e.g. JSON) so that you can fetch it from your android application via a http call, then you can display it.
    – JoSSte
    Nov 19 at 6:42


















  • you have gotten data to PHP. but PHP is running on your server. you need to present it in a format (e.g. JSON) so that you can fetch it from your android application via a http call, then you can display it.
    – JoSSte
    Nov 19 at 6:42
















you have gotten data to PHP. but PHP is running on your server. you need to present it in a format (e.g. JSON) so that you can fetch it from your android application via a http call, then you can display it.
– JoSSte
Nov 19 at 6:42




you have gotten data to PHP. but PHP is running on your server. you need to present it in a format (e.g. JSON) so that you can fetch it from your android application via a http call, then you can display it.
– JoSSte
Nov 19 at 6:42

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369502%2fandroid-plot-bar-chart-from-mysql-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369502%2fandroid-plot-bar-chart-from-mysql-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?