1. Download Achartengine Library http://code.google.com/p/achartengine/downloads/list 2.graphicalview Graphicalview;graphicalview=chartfactory.getbarchartview (Getbasecontext (), dataset, renderer, type);//Histogram Graphicalview=chartfactory.getpiechartview (Getbasecontext (), dataset, renderer);// Pie chart Annotations: A dataset represents a data source, renderer represents a render parameter, and type represents a 3. Set DataSet Data source string[] titles={"test"}; list<double[] > values=new ArrayList<double[]> (); values.add (new double[]{ 5120.0,21251.0,25610.0}); xymultipleseriesdataset dataset=buildbardataset (titles, values) ; protected xymultipleseriesdataset buildbardataset (string[] titles, list<double[] > values) { Xymultipleseriesdataset dataset = new xymultipleseriesdataset (); int length = titles.length; for (int i = 0; i < length; i++) { CategorySeries series = new Categoryseries (Titles[i]); double[] v = values.get (i); int seriesLength = v.length; for (int k = 0; k < serieslength; k++) { series.add (V[k]); } dataset.addseries (Series.toxyseries ()); } return dataset; }
4. Setting rendering parameters and types
Int[] Colors={color.blue};
Xymultipleseriesrenderer renderer=buildbarrenderer (colors);
Type Type=type.default;
Renderer.setzoomenabled (false);//How did it fail----Use the following method
Renderer.setzoomenabled (False, false);//Success Control--hehe
Setchartsettings (renderer, "I am the title of the Histogram", "", "Statistical results", 0, 6, 0, 30000);
Renderer.getseriesrendererat (0). Setdisplaychartvalues (True);
Renderer.getseriesrendererat (1). Setdisplaychartvalues (True);
Renderer.setxlabels (0);//Set the number of subscripts on the x-axis
Renderer.setylabels (10); Set the number of subscripts on the y-axis
Renderer.setxlabelsalign (Align.right);
Renderer.setylabelsalign (align.left);//y axis number indicates the coordinates or the right
Renderer.setpanenabled (False, false);//Set whether panning is allowed
Renderer.addxtextlabel (1 "Chengdu");//display text at the specified coordinates
Renderer.addxtextlabel (2 "Xi ' an");// Displays the literal at the specified coordinates
Renderer.addxtextlabel (3 "Fuping");// Displays text at the specified coordinates
//Renderer.clearxtextlabels () ;//Clear LABELS
//renderer.setzoomrate (1.1f) ;//Set the scaling ratio
renderer.setbarspacing (1f);// Set the spacing of the bars
//renderer.setlabelstextsize (30) ;//Set the size of the number on the axis
Renderer.setxlabelsangle ( 300.0f);//Set the text rotation angle to the text clockwise rotation
Renderer.setxlabelspadding (10);//Set the distance between the text and the axis
Renderer.setfitlegend (TRUE);//Adjust the appropriate position
Protected xymultipleseriesrenderer buildbarrenderer (int[] colors) { xymultipleseriesrenderer renderer = new xymultipleseriesrenderer (); Renderer.setaxistitletextsize (; ) Renderer.setcharttitletextsize (; ) Renderer.setlabelstextsize (; ) Renderer.setlegendtextsize ( int); length = colors.length; for (int i = 0; i < length; i++) { &Nbsp; simpleseriesrenderer r = new simpleseriesrenderer (); r.setcolor (Colors[i] ); Renderer.addseriesrenderer (R); } return renderer; }private void setchartsettings (Xymultipleseriesrenderer renderer, String title, String xlable, String ylable, int xmin, int Xmax, int ymin, int ymax) { renderer.setcharttitle (title); Renderer.setxtitle (xlable); renderer.setytitle (ylable); renderer.setxaxismin (xmin); Renderer.setxaxismax (xmax); renderer. Setyaxismin (ymin); renderer.setyaxismax (ymax); }
5. Load the Graphicalview into the layout
layout= (LinearLayout) Findviewbyid (r.id.linearlayout); Layout.removeallviews (); Layout.setbackgroundcolor ( Color.Black); Layout.addview (Graphicalview, New Layoutparams (layoutparams.fill_parent,layoutparams.fill_parent));
This article is from the "It Software Development Materials" blog, please be sure to keep this source http://491733638.blog.51cto.com/3913830/1659955
Android Development Chart Achartengine bar chart