The achartengine of the Android development series

Source: Internet
Author: User

Development of the Android chart control

A small program has been developed to develop an app on Android TV that displays information about some statistical charts. Finally looking for an Android native based on the development of Achartengine ready-made components available, and then directly import the jar package, look at the API documentation developed. Of course, this is just a client program, the source of the data needs to be obtained through the server-side program, in the project through WCF return data in JSON format.

Code Snippets

NewThread (NewRunnable () {@Override Public voidrun () {Soapobject soapobject=UTIL.CALLWS (NameSpace, METHODNAME2,WSDL,NULL); if(Soapobject! =NULL) {String result= Soapobject.getproperty (0). toString (); Message msg=NewMessage (); Msg.what=Chart2; Msg.obj=result;        Handler.sendmessage (msg); }}). Start ();
/** * @param nameSpace * WS namespace * @param method name of MethodName * WS * @param wsdl * The full pathname of the WS WSDL * @param the parameters required by the params * ws method * @return Soapobject Object*/     Public Staticsoapobject CALLWS (String nameSpace, String methodName, Final String wsdl, Map<string, object>params) {Final String soap_action= NameSpace +"/service/"+MethodName; Soapobject Soapobject=NewSoapobject (NameSpace, methodName); if((params!=NULL) && (!params. IsEmpty ())) {Iterator<entry<string, object>> it =params. EntrySet (). iterator ();  while(It.hasnext ()) {Map.entry<string, object> e = (map.entry<string, object>) it. Next ();            Soapobject.addproperty (E.getkey (), E.getvalue ()); }} final Soapserializationenvelope envelope=NewSoapserializationenvelope (SOAPENVELOPE.VER11); Envelope.bodyout=Soapobject; Envelope.dotnet=true;//compatible. NET-developed web ServiceEnvelope.setoutputsoapobject (Soapobject); Try{Httptransportse HT=NewHttptransportse (WSDL);            Ht.call (soap_action, envelope); if(Envelope.getresponse ()! =NULL) {soapobject result=(Soapobject) Envelope.bodyin; HT=NULL; returnresult; } Else {                return NULL; }        } Catch(Exception e) {LOG.E ("Error", E.getmessage ()); return NULL; }    }
String RESULT2 =(String) msg.obj;int[] Colors2 =New int[] {Color.argb (255,Ten, -,Bayi), Color.argb (255,182, the, the)};D efaultrenderer Renderer2=Sexchart.buildcategoryrenderer (colors2);//String result =//{\ "result_list\": [{\ "sex\": \ "other \", \ "num\": \ "1\"}, {\ "sex\": \ "male \", \ "num\": \ "37\"}, {\ "sex\": \ "female \", \ "num\": \ " 2\ "}]}";list<map<string, object>> list2 =util.convertjson2list (RESULT2,"result_list",NewString[] {"SEX","NUM" }); Categoryseries categoryseries=NewCategoryseries ("Vehicles Chart"); for(Map<string, object>map:list2) {categoryseries.add (map.Get("SEX"). ToString (), double.parsedouble (map.Get("NUM"). toString ()));} View View2= Chartfactory.getpiechartview (Main. This, Categoryseries, renderer2);if(View2! =NULL) {layout01.removeallviews ();   Layout01.destroydrawingcache (); Layout01.addview (VIEW2);} Else{toast.maketext (Main). This,"statistical result acquisition failed. ", Toast.length_long). Show ();}
 Public StaticList<map<string, object>>convertjson2list (String result,string name, string[] fields) {List<map<string, object>> list =NewArraylist<map<string, object>>(); Try{Jsonarray array=Newjsonobject (Result). Getjsonarray (name);  for(inti =0; I < Array.Length (); i++) {JsonobjectObject=(jsonobject) array.opt (i); Map<string, object> map =NewHashmap<string, object>();  for(String str:fields) {map.put (str,Object.Get(str));           } list.add (map); }        } Catch(jsonexception e) {LOG.E ("Error", E.getmessage ()); }    returnlist;}

Resources:

Http://www.achartengine.org/content/demo.html

Achartengine of the Android Development series

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.