Many times in the project we need to draw a table for some statistics, more intuitive view of the report analysis results. Basically there are several ways to do this:
1: Can be used for the Android API draw such words, less efficient
2: Use the open-source drawing table engine, which is more efficient. Here's an introduction.
Achartengine (ACE) is a Google Open Source Chart library (for Android). It is powerful and supports a variety of charts such as scatter, line, pie, bubble, histogram, short bar, gauge, and more.
The project address is located at: http://code.google.com/p/achartengine/
You can choose the appropriate version to download, each version has a jar package, instance source code and Java doc to provide download. Currently the latest version is 1.1.0.
Here are two examples of icons drawn with the engine.
As shown: You can have the demo source code, the documentation and the jar package, as needed to download:
Here's a little demonstration of generating a tree chart:
1: Create a new project and bring in the jar
2: Make configuration file in the Androidmanifest.xml file
<activity android:name= "Org.achartengine.GraphicalActivity"/>
Because the next thing to do is show the chart.
3: Create a Achart interface below
- Public interface Achartabstract {
- /**
- * Gets a intent instance of the current type icon
- */
- Public Intent getintent (context context);
- }
4: Create Barchart.java to prepare data source and engine settings
- Public class Barchart implements Achartabstract {
- Public Intent getintent (context context) {
- Intent mintent=chartfactory.getbarchartintent (context, GetDataSet (), Getrenderer (), type.stacked, "The Monthly invoice amount tree");
- return mintent;
- }
- /**
- * Construction Data
- * @return
- */
- Public Xymultipleseriesdataset GetDataSet () {
- //Construction data
- Xymultipleseriesdataset Bardataset = new Xymultipleseriesdataset ();
- Categoryseries barseries = new Categoryseries ("March 2014");
- Barseries.add (865.5969);
- Barseries.add (2492.6479);
- Barseries.add (891.0137);
- Barseries.add (0.0);
- Barseries.add (691.0568);
- Bardataset.addseries (Barseries.toxyseries ());
- return bardataset;
- }
- /**
- * Construct renderer
- * @return
- */
- Public Xymultipleseriesrenderer Getrenderer () {
- Xymultipleseriesrenderer renderer = new Xymultipleseriesrenderer ();
- Renderer.setcharttitle ("Invoicing of the Month");
- Set the font size for headings
- Renderer.setcharttitletextsize (16);
- Renderer.setxtitle ("business Unit");
- Renderer.setytitle ("unit (million)");
- Renderer.setaxescolor (Color.White);
- Renderer.setlabelscolor (Color.White);
- //Set the x-axis minimum and maximum numbers
- Renderer.setxaxismin (0.5);
- Renderer.setxaxismax (5.5);
- //Set the minimum and maximum numbers for the y-axis
- Renderer.setyaxismin (0);
- Renderer.setyaxismax (3000);
- Renderer.addxtextlabel (1, "power grid");
- Renderer.addxtextlabel (2, "Communication");
- Renderer.addxtextlabel (3, "broadband");
- Renderer.addxtextlabel (4, "Exclusive Network");
- Renderer.addxtextlabel (5, "rail intersection");
- Renderer.setzoombuttonsvisible (true);
- //Set renderer to allow zoom in and Zoom out
- Renderer.setzoomenabled (true);
- //anti-aliasing
- Renderer.setantialiasing (true);
- //Set background color
- Renderer.setapplybackgroundcolor (true);
- Renderer.setbackgroundcolor (Color.gray);
- //Set the color of each column
- simpleseriesrenderer sr = new Simpleseriesrenderer ();
- Sr.setcolor (Color.yellow);
- Renderer.addseriesrenderer (SR);
- //Set whether values are displayed on each pillar
- Renderer.getseriesrendererat (0). Setdisplaychartvalues (true);
- approximate number of coordinates of the//x-axis (this does not show the horizontal axis)
- Renderer.setxlabels (0);
- approximate number of coordinates of the//y-axis
- Renderer.setylabels (6);
- //tick marks align to the left of the x-axis text
- Renderer.setxlabelsalign (Align.left);
- //y-axis and y-axis coordinate text left aligned
- Renderer.setylabelsalign (Align.left);
- //Allow dragging left and right, but not allowed up or down.
- Renderer.setpanenabled (True, false);
- //width between pillars
- Renderer.setbarspacing (0.5f);
- //Set font size for x, Y axis units
- Renderer.setaxistitletextsize (20);
- return renderer;
- }
Finally, the main function directly
- Intent lineintent = new Barchart (). Getintent (this);
- StartActivity (lineintent);
Direct start Androidmanifest.xml already configured activity can display the tree chart.
The above note has been written more clearly. Basically, you can understand that. More examples of charts can be downloaded in the http://code.google.com/p/achartengine/demo
Android Chart Achartengine Learn to use with examples