Android 图表Rest Api数据未实时更新,
第一次正确加载数据,但第二次图形不会更新数据。 它一次又一次地显示以前的图形数据Android 图表Rest Api数据未实时更新,,android,graph,anychart,Android,Graph,Anychart,第一次正确加载数据,但第二次图形不会更新数据。 它一次又一次地显示以前的图形数据 public class OpdIpdAnalysis extends AppCompatActivity implements NetworkReceiver.ConnectionChangeCallback { AnyChartView anyChartView; Set set1; @Override protected void onCreate(Bundle savedInstance
public class OpdIpdAnalysis extends AppCompatActivity implements NetworkReceiver.ConnectionChangeCallback {
AnyChartView anyChartView;
Set set1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opd_ipd_analysis);
anyChartView = findViewById(R.id.anyChartLineChart);
anyChartView.setProgressBar(myProgressBar);
}
private void anyChartGraphViewData(Response<OpdIpdModel.ModelResponse> response) {
Cartesian cartesian = AnyChart.line();
cartesian.animation(true);
cartesian.padding(5d, 10d, 1d, 5d);
cartesian.crosshair().enabled(true);
cartesian.crosshair()
.yLabel(true)
// TODO ystroke
.yStroke((Stroke) null, null, null, (String) null, (String) null);
cartesian.tooltip().positionMode(TooltipPositionMode.POINT);
cartesian.title("MIS Report of comparing OPD and IPD data.");
//cartesian.yAxis(0).title("Number of Patient admitted in");
cartesian.xAxis(0).labels().padding(1d, 1d, 1d, 1d);
cartesian.xAxis(0).labels().fontSize(8);
/* Customization Done */
List<DataEntry> entries1 = new ArrayList<>();
//List<DataEntry> entries2 = new ArrayList<>();
final List<String> xLabel = new ArrayList<>();
if (response.body() != null) {
for (OpdIpdModel opdIpdModel : response.body().getOpdIpdComparison()) {
xLabel.add(opdIpdModel.getYear().shortValue() + "-" + opdIpdModel.getMonthString());
entries1.add(new CustomDataEntry(xLabel, opdIpdModel.getoPD(), opdIpdModel.getiPD()));
//entries2.add(new CustomDataEntry(xLabel, opdIpdModel.getoPD(), opdIpdModel.getiPD()));
}
}
set1 = Set.instantiate();
set1.data(entries1);
Mapping series1Mapping = set1.mapAs("{ x: 'x', value: 'value1' }");
//set2 = Set.instantiate();
//set2.data(entries2);
Mapping series2Mapping = set1.mapAs("{ x: 'x', value: 'value2' }");
Line series1 = cartesian.line(series1Mapping);
series1.name("OPD");
series1.hovered().markers().enabled(true);
series1.hovered().markers()
.type(MarkerType.CIRCLE)
.size(5d);
series1.tooltip()
.position("right")
.anchor(Anchor.LEFT_CENTER)
.offsetX(0d)
.offsetY(0d);
Line series2 = cartesian.line(series2Mapping);
series2.name("IPD");
series2.hovered().markers().enabled(true);
series2.hovered().markers()
.type(MarkerType.CIRCLE)
.size(5d);
series2.tooltip()
.position("right")
.anchor(Anchor.LEFT_CENTER)
.offsetX(0d)
.offsetY(0d);
cartesian.legend().enabled(true);
cartesian.legend().fontSize(10d);
cartesian.legend().padding(0d, 0d, 10d, 0d);
cartesian.interactivity().hoverMode(HoverMode.BY_X);
//cartesian.xZoom(3);
cartesian.xScroller(true);
//cartesian.notifyDataChanged();
anyChartView.setZoomEnabled(true);
anyChartView.setChart(cartesian);
anyChartView.refreshDrawableState();
anyChartView.invalidate();
//anyChartView.notify();
}
private class CustomDataEntry extends ValueDataEntry {
CustomDataEntry(List<String> x, Number value, Number value2) {
super(String.valueOf(x), value);
setValue("value1", value);
setValue("value2", value2);
}
}
private void allOpdIpdData(String department_id) {
call = service.getAllOpdIpdData("/Report/GetOpdIpdComparison?departmentId=" + department_id);
call.enqueue(new Callback<OpdIpdModel.ModelResponse>() {
@Override
public void onResponse(@NotNull Call<OpdIpdModel.ModelResponse> call, @NotNull Response<OpdIpdModel.ModelResponse> response) {
myProgressBar.setVisibility(View.GONE);
if (response.isSuccessful() && response.body() != null) {
updateUI(response.body().getOpdIpdComparison());
//graphData(response);
/*if (anyChartView != null && anyChartView.isEnabled()){
anyChartView.clear();
}*/
anyChartGraphViewData(response);
} else {
if (response.code() == 401) {
}
}
}
@Override
public void onFailure(@NotNull Call<OpdIpdModel.ModelResponse> call, @NotNull Throwable t) {
}
});
}
}
public类OpdIpdAnalysis扩展AppCompatActivity实现NetworkReceiver.ConnectionChangeCallback{
任意图表视图任意图表视图;
设置set1;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opd_ipd_analysis);
anyChartView=findViewById(R.id.anyChartLineChart);
anyChartView.setProgressBar(myProgressBar);
}
私有void anyChartGraphViewData(响应){
笛卡尔笛卡尔=AnyChart.line();
笛卡尔动画(真);
笛卡尔填充(5d,10d,1d,5d);
cartesian.crosshair()已启用(true);
笛卡尔十字线
.yLabel(对)
//托多伊斯特罗克
.yStroke((笔划)null,null,null,(字符串)null,(字符串)null);
cartesian.tooltip().positionMode(TooltipPositionMode.POINT);
cartesian.title(“比较OPD和IPD数据的错误报告”);
//笛卡尔.yAxis(0).标题(“入院患者数量”);
笛卡尔.xAxis(0).labels().padding(1d,1d,1d,1d);
笛卡尔.xAxis(0).labels().fontSize(8);
/*定制完成*/
List entries1=新的ArrayList();
//List entries2=新的ArrayList();
最终列表xLabel=newarraylist();
if(response.body()!=null){
for(optdipdmodel optdipdmodel:response.body().getoptdipdcomparison()){
xLabel.add(opdIpdModel.getYear().shortValue()+“-”+opdIpdModel.getMonthString());
entries1.add(新的CustomDataEntry(xLabel,opdIpdModel.getoPD(),opdIpdModel.getiPD());
//添加(新的CustomDataEntry(xLabel,opdIpdModel.getoPD(),opdIpdModel.getiPD());
}
}
set1=Set.instantiate();
set1.数据(entries1);
映射序列1Mapping=set1.mapAs(“{x:'x',value:'value1'}”);
//set2=Set.instantiate();
//set2.数据(entries2);
映射序列2mapping=set1.mapAs(“{x:'x',value:'value2'}”);
线系列1=笛卡尔线(系列1映射);
系列1.名称(“OPD”);
序列1.hovered().markers().enabled(true);
series1.hovered().markers()
.type(MarkerType.CIRCLE)
.尺寸(5d);
系列1.工具提示()
.位置(“右”)
.锚定(锚定左_中心)
.offsetX(0d)
.offsetY(0d);
线系列2=笛卡尔线(系列2映射);
系列2.名称(“IPD”);
序列2.hovered().markers().enabled(true);
series2.hovered().markers()
.type(MarkerType.CIRCLE)
.尺寸(5d);
系列2.工具提示()
.位置(“右”)
.锚定(锚定左_中心)
.offsetX(0d)
.offsetY(0d);
cartesian.legend()已启用(true);
笛卡尔.legend().fontSize(10d);
笛卡尔.legend()填充(0d,0d,10d,0d);
cartesian.interactivity().hoverMode(hoverMode.BY_X);
//笛卡尔.xZoom(3);
笛卡尔.xScroller(真);
//notifyDataChanged();
anyChartView.setZoomEnabled(true);
anyChartView.setChart(笛卡尔);
anyChartView.refreshDrawableState();
anyChartView.invalidate();
//anyChartView.notify();
}
私有类CustomDataEntry扩展了ValueDataEntry{
CustomDataEntry(列表x,数字值,数字值2){
super(String.valueOf(x),value);
设置值(“值1”,值);
设置值(“值2”,值2);
}
}
私有void allopdipdata(字符串部门id){
call=service.getAllopDipdata(“/Report/getoptdipdcomparison?departmentId=“+department\u id”);
call.enqueue(新回调(){
@凌驾
公共void onResponse(@NotNull调用,@NotNull响应){
myProgressBar.setVisibility(View.GONE);
if(response.issusccessful()&&response.body()!=null){
updateUI(response.body().getoptdipdcomparison());
//图形数据(响应);
/*if(anyChartView!=null&&anyChartView.isEnabled()){
anyChartView.clear();
}*/
anyChartGraphViewData(响应);
}否则{
if(response.code()==401){
}
}
}
@凌驾
public void onFailure(@NotNull Call Call,@NotNull Throwable t){
}
});
}
}
我正在使用试用版,如何用新数据重新加载折线图
有什么想法吗?为什么会这样?如何解决这个问题
请帮我解决这个问题
谢谢。无需重新创建图表来更新数据。您只需将新数据应用于现有图表。以前也提出过同样的问题,我在下面的评论中提出了解决办法。请检查,这应该对您有帮助。我是新来的,您能给我看一些代码吗,我不明白,我哪里做错了!