Android Chart Achartengine Learn to use with examples

Source: Internet
Author: User
Tags set background

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

    1. Public interface Achartabstract {
    2. /** 
    3. * Gets a intent instance of the current type icon
    4. */
    5. Public Intent getintent (context context);
    6. }

4: Create Barchart.java to prepare data source and engine settings

  1. Public class Barchart implements Achartabstract {
  2. Public Intent getintent (context context) {
  3. Intent mintent=chartfactory.getbarchartintent (context, GetDataSet (), Getrenderer (), type.stacked, "The Monthly invoice amount tree");
  4. return mintent;
  5. }
  6. /** 
  7. * Construction Data
  8. * @return
  9. */
  10. Public Xymultipleseriesdataset GetDataSet () {
  11. //Construction data
  12. Xymultipleseriesdataset Bardataset = new Xymultipleseriesdataset ();
  13. Categoryseries barseries = new Categoryseries ("March 2014");
  14. Barseries.add (865.5969);
  15. Barseries.add (2492.6479);
  16. Barseries.add (891.0137);
  17. Barseries.add (0.0);
  18. Barseries.add (691.0568);
  19. Bardataset.addseries (Barseries.toxyseries ());
  20. return bardataset;
  21. }
  22. /** 
  23. * Construct renderer
  24. * @return
  25. */
  26. Public Xymultipleseriesrenderer Getrenderer () {
  27. Xymultipleseriesrenderer renderer = new Xymultipleseriesrenderer ();
  28. Renderer.setcharttitle ("Invoicing of the Month");
  29. Set the font size for headings
  30. Renderer.setcharttitletextsize (16);
  31. Renderer.setxtitle ("business Unit");
  32. Renderer.setytitle ("unit (million)");
  33. Renderer.setaxescolor (Color.White);
  34. Renderer.setlabelscolor (Color.White);
  35. //Set the x-axis minimum and maximum numbers
  36. Renderer.setxaxismin (0.5);
  37. Renderer.setxaxismax (5.5);
  38. //Set the minimum and maximum numbers for the y-axis
  39. Renderer.setyaxismin (0);
  40. Renderer.setyaxismax (3000);
  41. Renderer.addxtextlabel (1, "power grid");
  42. Renderer.addxtextlabel (2, "Communication");
  43. Renderer.addxtextlabel (3, "broadband");
  44. Renderer.addxtextlabel (4, "Exclusive Network");
  45. Renderer.addxtextlabel (5, "rail intersection");
  46. Renderer.setzoombuttonsvisible (true);
  47. //Set renderer to allow zoom in and Zoom out
  48. Renderer.setzoomenabled (true);
  49. //anti-aliasing
  50. Renderer.setantialiasing (true);
  51. //Set background color
  52. Renderer.setapplybackgroundcolor (true);
  53. Renderer.setbackgroundcolor (Color.gray);
  54. //Set the color of each column
  55. simpleseriesrenderer sr = new Simpleseriesrenderer ();
  56. Sr.setcolor (Color.yellow);
  57. Renderer.addseriesrenderer (SR);
  58. //Set whether values are displayed on each pillar
  59. Renderer.getseriesrendererat (0). Setdisplaychartvalues (true);
  60. approximate number of coordinates of the//x-axis (this does not show the horizontal axis)
  61. Renderer.setxlabels (0);
  62. approximate number of coordinates of the//y-axis
  63. Renderer.setylabels (6);
  64. //tick marks align to the left of the x-axis text
  65. Renderer.setxlabelsalign (Align.left);
  66. //y-axis and y-axis coordinate text left aligned
  67. Renderer.setylabelsalign (Align.left);
  68. //Allow dragging left and right, but not allowed up or down.
  69. Renderer.setpanenabled (True, false);
  70. //width between pillars
  71. Renderer.setbarspacing (0.5f);
  72. //Set font size for x, Y axis units
  73. Renderer.setaxistitletextsize (20);
  74. return renderer;
  75. }


Finally, the main function directly

    1. Intent lineintent = new Barchart (). Getintent (this);
    2. 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

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