First of all to download the Acharengine package, which is important to have Lib and some simple tools, and so I attached to the folder, and these packages must be called.
Then the main drawing code is attached as follows:
Package Org.achartengine.chartdemo.demo.chart; Import java.util.ArrayList; Import java.util.List; Import Org.achartengine.ChartFactory; Import Org.achartengine.chart.PointStyle; Import Org.achartengine.renderer.XYMultipleSeriesRenderer; Import Org.achartengine.renderer.XYSeriesRenderer; Import Android.content.Context; Import android.content.Intent; Import Android.graphics.Color; Import android.graphics.Paint.Align; public class Averagetemperaturechart extends Abstractdemochart {public String getName () {return "Average Tempe Rature "; } public String GetDesc () {return ' The average temperature in 4 Greek Islands (line chart) "; } public Intent execute (context context) {string[] titles = new string[] {"Crete", "CORFU", "Thassos", "Skiath OS "};//legend list<double[]> x = new arraylist<double[]> (); for (int i = 0; i < titles.length; i++) {X.add (new double[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});//In each sequenceThe x-coordinate of the point} list<double[]> values = new arraylist<double[]> (); Values.add (new double[] {12.3, 12.5, 13.8, 16.8, 20.4, 24.4, 26.4, 26.1, 23.6, 20.3, 17.2, 13.9});//The y-coordinate of the midpoint of the sequence 1 Values.add (New double[] {10, 10, 12, 15, 20, 24, 26, 26, 23, 18, 14, 11});//The y-coordinate of the midpoint of sequence 2 values.add (new double[] { 5, 5.3, 8, 12, 17, 22, 24.2, 24, 19, 15, 9, 6});//The y-coordinate of the midpoint of sequence 3 Values.add (new double[] {9, 10, 11, 15, 19, 23, 26, 25 , 22, 18, 13, 10});//y-coordinate of sequence 4 midpoint int[] colors = new int[] {color.blue, Color.green, Color.cyan, Color.yellow};//each order Column color settings pointstyle[] styles = new pointstyle[] {pointstyle.circle, Pointstyle.diamond, Pointstyle.triangle, Pointstyle.square};//The shape setting of the midpoint of each sequence xymultipleseriesrenderer renderer = buildrenderer (colors, styles);//Call Abstractdem The method in ochart sets the renderer. int length = Renderer.getseriesrenderercount (); for (int i = 0; i < length; i++) {((xyseriesrenderer) Renderer.getseriesrendererat (i)). SetfiLlpoints (TRUE);//Set the point on the graph to be solid} setchartsettings (renderer, "Average temperature", "Month", "Temperature", 0.5, 12.5 , -10, Color.ltgray, Color.ltgray);//Call the method in Abstractdemochart to set the Renderer property of the chart. Renderer.setxlabels (12);//Set the x-axis to show 12 points, according to the maximum value of setchartsettings and the minimum value of their own initiative to calculate the interval renderer.setylabels (10);//Set the y-axis to display 10 points, Automatically calculates the interval Renderer.setshowgrid (true) of the point based on the maximum and minimum values of the setchartsettings;//whether the grid renderer.setxlabelsalign (align.right) is displayed; The relative position relationship between tick marks and tick marks renderer.setylabelsalign (align.center);//The relative position relationship between tick marks and scale labels renderer.setzoombuttonsvisible (tru e);//whether the Zoom Zoom button renderer.setpanlimits (new double[] {-10, 20,-10, 40}) is displayed; Sets the maximum minimum value for the x-axis y-axis that is agreed when dragging. Renderer.setzoomlimits (New double[] {-10, 20,-10, 40});//Set the maximum minimum value that the x-axis y-axis agrees on when zooming in and out. Intent Intent = chartfactory.getlinechartintent (context, Builddataset (titles, x, values), renderer, "Average temp erature111 ");//build intent return intent; } }
One thing to note is that this return is intent, which means there must be a main activity to be passed. My main activity is attached below:
Package Com.example.acharengine;import Android.app.activity;import Android.content.intent;import android.os.Bundle Import Android.view.view;import Android.widget.button;public class Mainactivity extends Activity {private Button BTN = null; @Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); BTN = (Button) Findviewbyid (r.id.button1); Btn.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method Stubaveragetemperaturechart Intent = new Averagetemperaturechart (); Intent mintent = Intent.execute ( Mainactivity.this); startactivity (mintent);}});}
As for XML, just have a button to jump over it:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " tools:context= "${packagename}.${activityclass}" > <textview android:id= "@+id/textview1" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "@string/hello_ World "/> <button android:id=" @+id/button1 " android:layout_width= " Wrap_content " android:layout_height= "Wrap_content" android:layout_below= "@+id/textview1" android:layout_marginleft = "33DP" android:layout_margintop= "56DP" android:layout_torightof= "@+id/textview1" android:text= "Button"/></relativelayout>
Again, two important packages, one LIB and one package Org.achartengine.chartdemo.demo.chart, must be redeployment.
Don't forget to add <activity android:name= "org.achartengine.GraphicalActivity"/> This activity in manifest.
: http://download.csdn.net/detail/modiziri/8179119
Similar article site: http://www.apkway.com/thread-6363-1-1.html
Using Acharengine as an Android chart