Achartengine is a good graph report development library on the Android platform. Address of the project: http://code.google.com/p/achartengine. The latest version is 1.0. Each version has a corresponding jar package, demo, and Java Doc. The examples in the demo are already very detailed. You can download the demo and import it to eclipse. Here I will make an example and add a comment.
In the demo, there is a class of abstractdemochart. Java, which can be used as a parent class. You can inherit from this class when drawing any graph. There are two main aspects of drawing, one is dataset, that is, the dataset, such as the x/y axis value, and the other is Renderer, that is, the Renderer, such as the font color, size, and so on. This parent class contains some basic methods for creating dataset and Renderer. Of course, you can modify it as needed. Finally, generate the corresponding chart using the corresponding method of the chartfactory class, such as getlinechartintent (..) generate a linear table. The returned result is an intent, which can be started directly. However, you must add <Activity
Android: Name = "org. achartengine. graphicalactivity"/>. You can also use getlinechartview (...) of chartfactory to return the view object of a linear table, so that you can put this view object in a layout for display. The following is the sample code:
Public class averagetemperaturechart extends actdemochart {Public String getname () {return "average temperature";} Public String getdesc () {return "the average temperature in 4 Greek islands (line chart) ";}/*** executes the chart demo. ** @ Param context * the context * @ return the built intent */public intent execute (context) {// titlestring [] titles = new string [] {"Crete "," Corfu "," Thassos "," skiathos "}; // list of X axis values <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 });} // list of values of the Y axis <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}); values. add (New Double [] {10, 10, 12, 15, 20, 24, 26, 26, 23, 18, 14,11}); values. add (New Double [] {5, 5.3, 8, 12, 17, 22, 24.2, 24, 19, 15, 9, 6}); values. add (New Double [] {9, 10, 11, 15, 19, 23, 26, 25, 22, 18, 13, 10 }); int [] colors = new int [] {color. blue, color. green, color. cyan, color. yellow}; // vertex style pointstyle [] styles = new pointstyle [] {pointstyle. circle, pointstyle. diamond, pointstyle. triangle, pointstyle. square}; xymultipleseriesrenderer re Nderer = buildrenderer (colors, Styles); int length = Renderer. getseriesrenderercount (); // whether the point is hollow or solid for (INT I = 0; I <length; I ++) {(xyseriesrenderer) Renderer. getseriesrendererat (I )). setfillpoints (true);} // the background color Renderer in the chart. setbackgroundcolor (color. parsecolor ("# f3f3f3"); Renderer. setapplybackgroundcolor (true); // the padding color between the chart and the four sides of the screen Renderer. setmarginscolor (color. argb (0, 0xf3, 0xf3, 0xf3); Renderer. setch Arttitletextsize (30); Renderer. setaxistitletextsize (25); // Renderer. setlegendheight (50); // legend text size Renderer. setlegendtextsize (20); Renderer. setmargins (New int [] {50, 50, 50, 30}); // The Renderer on the Y axis and X. setxlabelscolor (color. black); Renderer. setylabelscolor (0, color. black); // The last two parameters represent the axis color and the axis label color setchartsettings (Renderer, "average temperature", "month", "temperature", 0.5, 12.5, -10, 40, color. black, Col Or. black); // Number of numbers on the axis Renderer. setxlabels (12); Renderer. setylabels (10); // whether to display the grid Renderer. setshowgrid (true); // the direction of the number on the X or Y axis, opposite. Renderer. setxlabelsalign (align. right); Renderer. setylabelsalign (align. right); // problematic method // Renderer. setzoombuttonsvisible (true); // Renderer. setpanlimits (New Double [] {-10, 20,-10, 40}); // Renderer. setzoomlimits (New Double [] {-10, 20,-10, 40}); intent = chartfactory. getlinechartintent (context, builddataset (titles, X, values), Renderer, "average temperature"); Return intent ;}}
In the code
renderer.setZoomButtonsVisible(true);
This method is problematic, and an error will be reported when it is added. This method displays the zoom button. Some methods can be modified to see the effect. For other charts, see the official demo.
Attached: