Android Column Chart

Source: Internet
Author: User

The column chart uses a achartengine.

The Achartengine-1.0.0.jar package needs to be referenced. : http://download.csdn.net/detail/yaohucaizi/5128672. The specific code is as follows:

 Public classXymultipleactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (r.layout.activity_xymultiple); //Initial DataString[] Titles =NewString[] {"2008", "2007" }; List<Double[]> values =Newarraylist<Double[]>(); Values.add (New Double[] {14230, 12300, 14240, 15244, 15900, 19200, 22030, 21200, 19500, 15500, 12600, 14000 }); Values.add (New Double[] {5230, 7300, 9240, 10540, 7900, 9200, 12030, 11200, 9500, 10500, 11600, 13500 }); int[] Colors =New int[] {color.blue, Color.cyan}; //graphic StyleXymultipleseriesrenderer renderer =buildbarrenderer (colors); Setchartsettings (Renderer,"Monthly sales in the last 2 years", "Month", "Units sold",                    0.5, 12.5, 0, 24000, Color.gray, Color.ltgray); Renderer.getseriesrendererat (0). Setdisplaychartvalues (true);//set whether values are displayed above the barRenderer.getseriesrendererat (1). Setdisplaychartvalues (true); Renderer.setxlabels (12);//set the number of tick labels displayed on the x-axisRenderer.setylabels (10);//sets the number of tick labels displayed on the y-axisRenderer.setxlabelsalign (Align.left);//set the relative position relationship between tick marks and X-axesRenderer.setylabelsalign (Align.left);//set the relative position relationship between the tick marks and the y-axisRenderer.setpanenabled (true,false); Renderer.setzoomenabled (false); Renderer.setzoomrate (1.1F);//magnificationRenderer.setbarspacing (0.5f);//two The distance between the columnsView View= Chartfactory.getbarchartview ( This, Buildbardataset (titles, values), renderer, type.default);//type.stackedView.setbackgroundcolor (Color.Black);    Setcontentview (view); }     protectedXymultipleseriesdataset Buildbardataset (string[] titles, list<Double[]>values) {Xymultipleseriesdataset DataSet=NewXymultipleseriesdataset (); intLength =titles.length;  for(inti = 0; i < length; i++) {Categoryseries series=Newcategoryseries (Titles[i]); Double[] v =Values.get (i); intSerieslength =v.length;  for(intk = 0; K < Serieslength; k++) {Series.add (v[k]);            } dataset.addseries (Series.toxyseries ()); }            returnDataSet; }        protectedXymultipleseriesrenderer Buildbarrenderer (int[] colors) {Xymultipleseriesrenderer renderer=NewXymultipleseriesrenderer (); Renderer.setaxistitletextsize (16);//Set axis title text sizeRenderer.setcharttitletextsize (20);//Set Chart title text sizeRenderer.setlabelstextsize (15);//Set axis label text sizeRenderer.setlegendtextsize (15);//set legend Text size            intLength =colors.length;  for(inti = 0; i < length; i++) {Simpleseriesrenderer R=NewSimpleseriesrenderer ();                R.setcolor (Colors[i]);            Renderer.addseriesrenderer (R); }            returnrenderer; }               protected voidsetchartsettings (Xymultipleseriesrenderer renderer, string title, String Xtitle, String ytitle,DoubleXMin,DoubleXmax,Doubleymin,DoubleYMax,intAxescolor,intLabelscolor) {Renderer.setcharttitle (title);//Set icon nameRenderer.setxtitle (Xtitle);//set X axis nameRenderer.setytitle (Ytitle);//Set the y-axis nameRenderer.setxaxismin (XMin);//set the minimum value of the x-axisRenderer.setxaxismax (Xmax);//set the maximum value of the x-axisRenderer.setyaxismin (ymin);//set the minimum value of the y-axisRenderer.setyaxismax (YMax);//set the maximum value of the y-axisRenderer.setaxescolor (Axescolor);//Set the axis colorRenderer.setlabelscolor (Labelscolor); }    }

Main style settings for column charts:

1. Modify background color or set background picture background color settings need to set two items: Setmarginscolor (set four-sided color) and SetBackgroundColor (set intermediate background color) Set background image: http://blog.csdn.net/kmyhy/article/details/65902942. Setaxistitletextsize (16);//Set axis title text size3. Setcharttitletextsize (20);//Set Chart title text size4. Setlabelstextsize (15);//Set axis label text size5. Setlegendtextsize (15);//set legend Text size6. Renderer.setcharttitle ("Personal balance sheet");//Set Column chart name7. Renderer.setxtitle ("list");//set X axis name8. Renderer.setytitle ("Amount");//Set the y-axis name9. Renderer.setxaxismin (0.5);//set the minimum value for the X axis to 0.5Renderer.setxaxismax (5.5);//set the maximum value for the x-axis to 5Renderer.setyaxismin (0);//set the minimum value for the y-axis to 0Renderer.setyaxismax (500);//Set the y-axis maximum value toRenderer.setdisplaychartvalues (true);//set whether values are displayed above the barRenderer.setshowgrid (true);//set whether the grid is displayed in the chartRenderer.setxlabels (0);//set the number of tick labels displayed on the x-axis16. If you want to display a custom label on the x-axis, first set the Renderer.setxlabels (0second, we want to Renderer.addtextlabel () loop addRenderer.setxlabelsalign (Align.right);//set the relative position relationship between tick marks and X-axesRenderer.setylabelsalign (Align.right);//set the relative position relationship between the tick marks and the y-axisRenderer.setzoombuttonsvisible (true);//settings can be scaledRenderer.setpanlimits (newdouble[] {0, 20, 0, 140});//set the Pull rangeRenderer.setzoomlimits (newdouble[] {0.5, 20, 1, 150});//Set the extent of the zoomRenderer.setrange (newdouble[]{0d, 5d, 0d, 100d});//set the view range for a chartRenderer.setfitlegend (true);//Adjust the right positionRenderer.setclickenabled (true)//set Whether you can slide and zoom out;25. Description of the dataset and render parameters: http://blog.csdn.net/lk_blog/article/details/764566126. Chartview.repaint (); is the command to re-draw27. For Achartengine Click events, double-click events, swipe events can be resolved with custom events, but it is important to note that you set the renderer.setclickenabled first (false);28. If you are morphing after adding graphics, you can set Renderer.setinscroll (true);29.renderer.setgridcolor ();//Set the grid color30.renderer.setaxescolor ();//Set the axis color

Android Column Chart

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.