Using the Andbase development framework for drawing line graphs

Source: Internet
Author: User
Tags polyline

In Android, when there is a need to draw a line chart, most people use the achartengine to draw a line chart. The Achartengine Chart engine does have the ability to implement a line chart, and in addition to this, we can use the chart module inside the Andbase development framework to make the icon drawing. The previous article introduced the use of the Andbase development framework to implement the slide-bar effect, today, we learn how to implement the line drawing.

First, let's take a look at



We are simulating a company in 12 months, two different business sales changes, you can see, the effect is very good.

Below, we begin to show how to use andbase to achieve this effect.

First, let's look at the structure of the project, very simple structure


Just one XML, one activity, plus the andbase framework. Let's look at the layout file first

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:id= "@+id/chart    " Android:layout_width= "Match_parent"    android:layout_height= "match_parent"    android:orientation= " Vertical "></LinearLayout>

Also very simple, there is only one linear layout file.

The main thing is in the activity, the following code and comments

/** * * @ClassName: Mainactivity * @Description: andbase Framework Implementation Table drawing * @author: Zhaokaiqiang * @time: 2014-7-17 3:21:11 * @ version:v1.0 */public class Mainactivity extends Activity {private LinearLayout linearlayout;//polyline description text private string[] Ti TLEs = new string[] {"Business One", "Business II"};//data private list<double[]> values;//The color of each data point private list<int[]> colors; A brief description of each data point private list<string[]> explains;//polyline Line Color private int[] mseriescolors;//renderer Private Xymultipleseriesrenderer renderer; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); linearlayout = (linearlayout) findViewById (R.id.chart) ; Initvalues ();d Rawchart ();} /** * Initialize data */private void Initvalues () {values = new arraylist<double[]> (); colors = new arraylist<int[]> (); ex Plains = new Arraylist<string[]> () Values.add (new double[] {500, 450, 700, 710, 420, 430, 400, 390, 290,400, 340, 5 XX}); Values.add (new double[] {523, 450, 370, 480, 570, 420, 400,450, 710, A. Colors.add}); (new int[] {color.red, color.red, Color.Red, Color.red,co Lor. RED, Color.Red, Color.Red, Color.Red, color.red,color.red, color.red, color.red}); Colors.add (new int[] {Color.BLUE, Col Or. BLUE, Color.Blue, Color.blue,color.green, Color.Blue, Color.Blue, Color.Blue, Color.blue,color.blue, Color.BLUE, Color.Blue}); Explains.add (new string[] {"January results", "February results", "March results", "April results", "May results", "June results", "July results", "August results", "September results", "October results", "November results", "December Results"}); Explains.add (new string[] {"January results", "February results", "March results", "April results", "May results", "June results", "July results", "August results", "September results", "10 Monthly results ", November results", "December Results"}); mseriescolors = new int[] {Color.rgb (153, 204, 0), Color.rgb (247, 185, 64)};} /** * Starts plotting line chart */private void Drawchart () {renderer = new xymultipleseriesrenderer (); int length = Mseriescolors.length;for ( int i = 0; i < length; i++) {//Create Simpleseriesrenderer single renderer xyseriesrenderer r = new Xyseriesrenderer ();//Set renderer color R.setcolor (mseriescolors[i] ); R.setfillpoints (true);R.setpointstyle (Pointstyle.square); r.setlinewidth (1); r.setchartvaluestextsize (+); Renderer.addseriesrenderer (R );} Axis Title Text size renderer.setaxistitletextsize (16);//graphic title text size renderer.setcharttitletextsize (25);// The size of the label text on the axis renderer.setlabelstextsize (15);//Description Text size renderer.setlegendtextsize (15);//Chart title Renderer.setcharttitle (" Company 2014 sales Performance Line chart ");//x-axis title Renderer.setxtitle (" Time/month ");//y-axis title renderer.setytitle (" Sales/Wan Yuan ");// X-axis Minimum coordinate point renderer.setxaxismin (0);//x-axis maximum coordinate point Renderer.setxaxismax (n);//y-axis Minimum coordinate point renderer.setyaxismin (0);// Y-axis Maximum coordinate point Renderer.setyaxismax (800);//Axis Color Renderer.setaxescolor (Color.rgb (Wuyi, 181, 229)); Renderer.setxlabelscolor ( Color.rgb (Wuyi, 181, 229)); Renderer.setylabelscolor (0, Color.rgb (51, 181, 229));// Sets the caption on the chart and the x-axis and y-axis text color renderer.setlabelscolor (color.gray);//sets the font bold Renderer.settexttypeface ("Sans_serif", Typeface.bold);//sets whether the value label is displayed on the chart renderer.getseriesrendererat (0). Setdisplaychartvalues (True); Renderer.getseriesrendererat (1). Setdisplaychartvalues (true);//display screen the number of XY segments of the visible viewport Renderer.setxlabels (12); Renderer.setylabels (8);//X-scale label relative x-axis position renderer.setxlabelsalign (align.center);// The Y-tick label is relative to the y-axis position renderer.setylabelsalign (align.left); Renderer.setpanenabled (true, true); Renderer.setzoomenabled (True ); Renderer.setzoombuttonsvisible (true); Renderer.setzoomrate (1.1f); renderer.setbarspacing (0.5f);// The ruler turns on renderer.setscalelineenabled (true);//Set the ruler Tip box High renderer.setscalerectheight (10);// Set Ruler Tip box width renderer.setscalerectwidth (150);//Set ruler hint box background color renderer.setscalerectcolor (COLOR.ARGB (150, 52, 182, 232)); Renderer.setscalelinecolor (Color.argb (175), Renderer.setscalecircleradius (35);// The size of the first line of text renderer.setexplaintextsize1 (20);//The size of the second line of text renderer.setexplaintextsize2 (20);//Critical line double[] Limit = new Double[] {15000, 12000, 4000, 9000};renderer.setmylimitsline (limit); int[] Colorslimit = new int[] {COLOR.RGB (100, 255, 255), Color.rgb (255, 255), Color.rgb (0, 255, 255), Color.rgb (0, 255, 255)};renderer.setmylimitslinecolor ( COLORSLIMIT);//Display the table line Renderer.setshowgrid (TRUE);//If the value is 0 whether to display RENDERER.SETDISplayValue0 (TRUE);//Create renderer data filler xymultipleseriesdataset mxymultipleseriesdataset = new Xymultipleseriesdataset (); for (int i = 0; i < length; i++) {Categoryseries series = new Categoryseries (titles[i]);d ouble[] v = values.get (i); int[] C = colors.get (i); String[] e = Explains.get (i), int serieslength = v.length;for (int k = 0; k < serieslength; k++) {//sets the color of each point series.add ( V[k], c[k], e[k]);} Mxymultipleseriesdataset.addseries (Series.toxyseries ());} Background Renderer.setapplybackgroundcolor (true); Renderer.setbackgroundcolor (Color.rgb (222, 222, 200)); Renderer.setmarginscolor (Color.rgb (222, 222, 200));//Line graph View chart = Chartfactory.getlinechartview (This, Mxymultipleseriesdataset, renderer); Linearlayout.addview (chart);}}

The notes are clear and not too much to introduce.

Originally wanted to upload the source code, but the CSDN download channel and hung off ...

If you need a message, I'm uploading it.


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.