To undertake the previous article, please refer to http://blog.csdn.net/shineflowers/article/details/44701645
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.
<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:14PX;" >package Com.example.mpandroidlinechart;import Java.util.arraylist;import Com.github.mikephil.charting.charts.linechart;import Com.github.mikephil.charting.components.legend;import Com.github.mikephil.charting.components.legend.legendform;import Com.github.mikephil.charting.data.entry;import Com.github.mikephil.charting.data.linedata;import Com.github.mikephil.charting.data.linedataset;import Android.support.v7.app.actionbaractivity;import Android.graphics.color;import Android.graphics.Typeface;import Android.os.bundle;public class Mainactivity extends Actionbaractivity {private Linechart mlinechart;private Typeface mTf; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Mlinechart = (Linechart) Findviewbyid (r.id.spread_line_chart); mTf = Typeface.createfromasset (Getassets (), "Opensans-bold.ttf"); Linedata Mlinedata = Getlinedata (+); Showchart (MlinEchart, Mlinedata, Color.rgb (114, 188, 223));} Sets the style of the display private void Showchart (Linechart linechart, linedata linedata, int color) {linechart.setdrawborders (false); Whether to add a border on the line chart//No description text linechart.setdescription ("line chart");//Data Description//If there is no data, it will show this, like the ListView emtpy View Linechart.setnodatatextdescription ("need to provide data for the chart."); enable/disable Grid background Linechart.setdrawgridbackground (false); Whether to show table color Linechart.setgridbackgroundcolor (Color.White & 0X70FFFFFF); The color of the table here is to give the color set a transparency//enable Touch gestures linechart.settouchenabled (true); Sets whether you can touch/enable scaling and dragging linechart.setdragenabled (true);//Whether you can drag linechart.setscaleenabled (Tru e);//Whether it is possible to scale//if disabled, scaling can be do on X-and y-axis separately linechart.setpinchzoom (false);//Li Nechart.setbackgroundcolor (color);//Set background//Add Data Linechart.setdata (Linedata); Set data//Get the Legend (onlyPossible after setting data) Legend Mlegend = Linechart.getlegend (); Set the scale chart indicator, that is, the value of the group Y//Modify the legend ...//mlegend.setposition (Legendposition.left_of_chart); Mlegend.setform (legendform.circle);//Style mlegend.setformsize (6f);//font Mlegend.settextcolor (color.white);//Color ML Egend.settypeface (MTF); Mlegend.settypeface (mTf);//font Linechart.animatex (2500); Animate immediately, x-axis}//Generate a data, private linedata getlinedata (int count, float range) {arraylist<string> xValues = New Arraylist<string> (); for (int i = 0; i < count; i++) {//X-axis displays the data, which by default uses a numeric subscript to display Xvalues.add ("" + i); }//y-axis data arraylist<entry> yvalues = new arraylist<entry> (); for (int i = 0; i < count; i++) {Float value = (float) (Math.random () * range) + 3; Yvalues.add (New Entry (value, i)); }//Create a dataset and give it a type//y-axis data collection Linedataset Linedataset = new Linedataset (yvalues, "Test Line chart"/* Show in scale chart(Upper/*); Mlinedataset.setfillalpha (110); Mlinedataset.setfillcolor (color.red); Set the parameter Linedataset.setlinewidth (1.75f) with the y-axis collection; Line width linedataset.setcirclesize (3f);//Display the circular size linedataset.setcolor (color.white);//Display Color Linedataset.setcirclecol or (color.white);//Round color linedataset.sethighlightcolor (color.white); The color of the highlighted line arraylist<linedataset> linedatasets = new arraylist<linedataset> (); Linedatasets.add (Linedataset); Add the Datasets//Create a data object with the datasets Linedata Linedata = new Linedata (xValues, Linedatasets ); return linedata;}} </span>as follows;
Mpandroidchart Open Source Chart Library (ii) line chart