Recently, we are using rchart to draw a graph on Android. Because data needs to be dynamically updated, we need to set the update interval. I have been exploring for a long time and can finally do it today. The referenced assets are all in the rchart demo. I just modified the refresh time. Rchart demo in my resources, for dynamic display data, you should remember to add the time statement in listener, for example:
Chartandroidimage. assets = getassets (); chartpanel = new chartpanel (view [I]. getcontext (); Chart chart = loadfromasset ("temperature"); chart. addchartlistener (New chartadapter () {@ overridepublic void chartevent (Chart C, int type) {// todo auto-generated method stubsuper. chartevent (C, type); C. msecs = 2000; If (type = chartlistener. event_before_update) {createrealtimedata (CHA, "8", "temperature");} If (type = chartlistener. event_after_update) {view [Kk]. postinvalidate (); // This rchart is displayed in pupopwindow, so you need to call postinvalidate }}); chart. startupdater (); chartpanel. setchart (Chart );
Createrealtimedata: Get Data
Private void createrealtimedata (chartloader loader, string ID, string type) {sensor = webservicemethod. getsensordatabyid (ID); If (sensor! = NULL) {double zuigao = double. parsedouble (sensor. getvaluebytype (type) + 2; double pingjun = double. parsedouble (sensor. getvaluebytype (type)-2; // The right side is the latest data maxdata = maxdata. substring (maxdata. indexof ("|") + 1) + "|" + zuigao; system. out. println (maxdata); loader. setparameter ("serie_data_1", maxdata); avgdata = avgdata. substring (avgdata. indexof ("|") + 1) + "|" + pingjun; system. out. println (avgdata); loader. setparameter ("serie_data_2", avgdata );}
Loadfromasset: Initialize the graph.
Public chart loadfromasset (string type) throws ioexception {system. out. println ("creating loader... "); Cha. setparameter ("width", "300"); Cha. setparameter ("height", "250"); Cha. setparameter ("titlechart", "Node" + Type + "display"); Cha. setparameter ("title_font", "serif | bold | 12"); Cha. setparameter ("ylabel", "degree Celsius"); Cha. setparameter ("yscale_min", "0"); Cha. setparameter ("tick_intervaly", "2"); // The distance between two small trick y axes, Cha. setparameter ("yaxis_tickatbase", "true"); // the Y axis trick starts from 0. setparameter ("xaxis_grid", "0.2 | 0xffffff | dashed"); Cha. setparameter ("yaxis_grid", "0.2 | 0xffffff | dashed"); Cha. setparameter ("gridy", "true"); // There is a grid Cha only in the big trick. setparameter ("big_tick_intervalx", "1"); // The number of small trick s between two large trick s on the X axis. Cha. setparameter ("xaxis_labels", "1 | 2 | 3 | 4 | 5 | 6"); Cha. setparameter ("xaxis_start_with_big_tick", "true"); Cha. setparameter ("yaxis_start_with_big_tick", "true"); Cha. setparameter ("legend_vertical", "false"); // display mode of legend. True indicates that Cha is displayed vertically. setparameter ("serie_1", "maximum value"); Cha. setparameter ("serie_2", "average"); Cha. setparameter ("serie_font_1", "Arial | plain | 8"); Cha. setparameter ("serie_font_2", "Arial | plain | 8"); Cha. setparameter ("serie_color_1", "Red"); Cha. setparameter ("serie_color_2", "blue"); Cha. setparameter ("serie_style_1", "2 | red | Line"); Cha. setparameter ("serie_style_2", "0.2 | Blue | Line"); Cha. setparameter ("serie_point_1", "true"); Cha. setparameter ("serie_point_2", "true"); Cha. setparameter ("serie_point_color_1", "Red"); Cha. setparameter ("serie_point_color_2", "blue"); Cha. setparameter ("legend_position", "bottom"); Cha. setparameter ("left_margin", "0.15"); Cha. setparameter ("right_margin", "0.05"); Cha. setparameter ("top_margin", "0.15"); Cha. setparameter ("bottom_margin", "0.09"); Cha. setparameter ("chart_border", "0.2 | 0x0 | normal"); Cha. setparameter ("chart_fill", "0 xeeffff"); Cha. setparameter ("chart_links_target", "_ Self"); Cha. setparameter ("serie_data_1", maxdata); Cha. setparameter ("serie_data_2", avgdata); log. I (chartpanel. tag, "Building chart... "); Chart C = CHA. build (false, false); log. I (chartpanel. tag, "Build OK"); Return C ;}
: Http://download.csdn.net/detail/yonghumingshishenme/3118685