Open alihit96 opened 5 years ago
@alihit96 Did I get your idea correctly that you are trying to update the existing chart data?
@Shestac92 yes
@alihit96 You should apply the new data to the chart. For details, please, check this example. It describes how to add new data to the chart.
If you are using any listener/delay for updating the chart, you should make the chart active by the following line:
APIlib.getInstance().setActiveAnyChartView(chartInstance);
This approach was discussed in the issue comment. Check previous comments for issue context.
@Shestac92 ok so I can now update my chart with my server data but it happens only once. the next time retrieve new data from server chart still shows the past data. here is my code:
public void getString(){
String url = "http://SERVER/somthing/somthing.php"+"?myDate="+finalDate;
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// Toast.makeText(getContext(),response.toString(),Toast.LENGTH_SHORT).show();
try {
JSONObject jsObject =response.getJSONObject("list3");
String sss =jsObject.getString("parkinsonism").trim();
String passive =jsObject.getString("hyperPassive").trim();
String active =jsObject.getString("hyperActive").trim();
String dystonia =jsObject.getString("dystonia").trim();
String akthisia =jsObject.getString("akthisia").trim();
String psychic =jsObject.getString("psychic").trim();
String motor =jsObject.getString("motor").trim();
if (!sss.equals("")){
parkinsonismServerValue = Integer.parseInt(sss);
}else {
parkinsonismServerValue =0;
}
if (!passive.equals("")) {
hyperPassiveServerValue = Integer.parseInt(passive);
}else {
hyperPassiveServerValue =0;
}
if (!active.equals("")){
hyperActiveServerValue = Integer.parseInt(active);
}else {
hyperActiveServerValue = 0;
}
if (!dystonia.equals("")){
dystoniaValue = Integer.parseInt(dystonia);
}else {
dystoniaValue = 0;
}
if (!akthisia.equals("")) {
akthisiaValue = Integer.parseInt(akthisia);
}else {
akthisiaValue = 0;
}
if (!psychic.equals("")) {
psychicValue = Integer.parseInt(psychic);
}else {
psychicValue = 0;
}
if (!motor.equals("")) {
motorValue = Integer.parseInt(motor);
}else {
motorValue = 0;
}
anyChartView =view.findViewById(R.id.bar_chart2);
anyChartView.setProgressBar(view.findViewById(R.id.progress_bar));
Cartesian cartesian = AnyChart.column();
APIlib.getInstance().setActiveAnyChartView(anyChartView);
List<DataEntry> data = new ArrayList<>();
data.add(new ValueDataEntry("PARKINSONISM", parkinsonismServerValue));
data.add(new ValueDataEntry("Passive", hyperPassiveServerValue));
data.add(new ValueDataEntry("Active", hyperActiveServerValue));
data.add(new ValueDataEntry("Dystonia", dystoniaValue));
data.add(new ValueDataEntry("vAkthia", akthisiaValue));
data.add(new ValueDataEntry("Psychic", psychicValue));
data.add(new ValueDataEntry("Motor", motorValue));
Column column = cartesian.column(data);
//Tooltip
column.tooltip()
.titleFormat("{%X}")
.position(Position.CENTER_TOP)
.anchor(Anchor.CENTER_TOP)
.offsetX(0d)
.offsetY(-60d)
.format("{%Value}{groupsSeparator: }");
cartesian.animation(true);
cartesian.title("Diagram View");
cartesian.contextMenu(true);
cartesian.yScale().minimum(0d);
cartesian.xAxis(0).labels(false);
cartesian.yAxis(0).labels().format("{%Value}{groupsSeparator: }");
cartesian.tooltip().positionMode(TooltipPositionMode.POINT);
cartesian.interactivity().hoverMode(HoverMode.BY_X);
cartesian.xAxis(0).title("Date");
cartesian.yAxis(0).title("Score");
anyChartView.setChart(cartesian);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Toast.makeText(getContext(),error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
}
@Shestac92 any idea what's wrong? Thank you
@alihit96
Does it execute getString ()
function every time you get new data?
Or there's another handler for updating the chart?
when I give the value like : data.add(new ValueDataEntry("example", 20); it works but when I recall the value from server and pass it to an int variable, then place it there like: data.add(new ValueDataEntry("example", somthing); it doesnt work! please help its necessary!