Android Development Chart Achartengine bar chart

Source: Internet
Author: User

1. Download Achartengine Library 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={};
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 (; 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

Android Development Chart Achartengine bar chart

Related Article

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: 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.