Mpandroidchart Open Source Chart Library (iii) column chart

Source: Internet
Author: User

to undertake the previous article, please refer to http://blog.csdn.net/shineflowers/article/details/44704723

1. Copy the Mpandroidchartlibrary-2-0-8.jar package to the project's Libs

2. Defining an XML file


3. The main Java logic code is as follows, and the comments have been added.

Package Com.jackie.mpandoidbarchart;import Java.util.arraylist;import Com.github.mikephil.charting.charts.barchart;import Com.github.mikephil.charting.components.legend;import Com.github.mikephil.charting.components.legend.legendform;import Com.github.mikephil.charting.data.BarData; Import Com.github.mikephil.charting.data.bardataset;import Com.github.mikephil.charting.data.barentry;import Android.support.v7.app.actionbaractivity;import Android.graphics.color;import Android.os.Bundle;public Class Mainactivity extends Actionbaractivity {private barchart mbarchart;private bardata mbardata; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Mbarchart = (barchart) Findviewbyid (r.id.spread_bar_chart); mbardata = Getbardata (4, +); Showbarchart (MBarChart, Mbardata);}  private void Showbarchart (Barchart barchart, BarData bardata) {barchart.setdrawborders (false); Whether to add border barchart.setdescription ("") on the line chart;// Data Description//If there is no data, it will show this, similar to the ListView Emptyview barchart.setnodatatextdescription ("You need to provide data fo                   R the chart. "); Barchart.setdrawgridbackground (FALSE); Whether to show table color Barchart.setgridbackgroundcolor (Color.White & 0X70FFFFFF); The color of the table, here is to give the color set a transparency barchart.settouchenabled (true); Sets whether you can touch barchart.setdragenabled (true), or whether you can drag barchart.setscaleenabled (true);//Whether you can scale barchart.se       Tpinchzoom (false);////barchart.setbackgroundcolor ();//Set Background Barchart.setdrawbarshadow (true); Barchart.setdata (BarData); Set data Legend mlegend = Barchart.getlegend (); Set the scale chart to mark Mlegend.setform (legendform.circle);//Style mlegend.setformsize (6f);//Font Mlegend . SetTextColor (Color.Black);//color Barchart.animatex (2500); Animation now performed, x-axis}private bardata getbardata (int count, float range) {arraylist<string> xValues = new Arraylist<stri Ng> (); for (int i = 0; I < COunt; i++) {Xvalues.add ("No." + (i + 1) + "quarter");}        arraylist<barentry> yvalues = new arraylist<barentry> ();            for (int i = 0; i < count; i++) {Float value = (float) (Math.random () * range/*100 within the random number */) + 3;            Yvalues.add (New Barentry (value, i));                 }//y-axis data set Bardataset Bardataset = new Bardataset (yvalues, "Test pie chart");            Bardataset.setcolor (Color.rgb (114, 188, 223));            arraylist<bardataset> bardatasets = new arraylist<bardataset> (); Bardatasets.add (Bardataset); Add the datasets BarData bardata = new BarData (xValues, bardatasets); return bardata;}}

as follows:


Mpandroidchart Open Source Chart Library (iii) 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.