Open source an Android custom chart library

Source: Internet
Author: User
Tags getcolor

      • Class library Access
      • Using the example
        • 1. Nightingale Rose Figure Nightingalerosechart
        • 2. Pie-like chart piechartlayout
        • 3, Progress ring diagram Progresspiechart
        • 4, longitudinal column chart Barverticalchart
        • 5, transverse column chart Barhorizontalchart
      • SOURCE download

?? There are some charting requirements in the project, and it's a good idea to start with some open source charting libraries that are powerful and have a wide variety of charts. However, these class libraries often require a lot of setup and do not fit well with the project style. So I try to write a chart library, it is very convenient to use, clear comments, late extensibility.

Class library Access

build.gradleAdd Dependencies in:

     implementation ‘com.openxu.viewlib:OXViewLib:<new version>‘
    • 1

Which <new version> is replaced with the latest version, version view Oxchart

Use Example 1, Nightingale Rose figure Nightingalerosechart

??????

<com.openxu.cview.chart.rosechart.NightingaleRoseChart    android:id="@+id/roseChartSmall"    android:layout_width="match_parent" android:layout_height="wrap_content"/>
Nightingalerosechart Rosechartsmall = (nightingalerosechart) Findviewbyid (R.id.rosechartsmall); Rosechartsmall.setshowchartlable (true);Whether the indicator Lablerosechartsmall.setshowchartnum is displayed on the chart (FALSE);Whether the indicator numrosechartsmall.setshownumtouched is displayed on the chart (FALSE);Click Show Quantity Rosechartsmall.setshowrightnum (true);Right Display quantity Roselist.add (New Rosebean (10,new Rosebean (13,  " Data 2 ")), Roselist.add (new Rosebean (31, new Rosebean (8,  "Data 4 "), Roselist.add (new Rosebean (21, //parameter 1: Data object class, Parameter 2: Quantity attribute field name, Parameter 3: Name attribute field name, Parameter 4: Data collection Rosechartsmall.setdata (rosebean.< Span class= "Hljs-keyword" >class,  "Count", false);             
2. Pie-like chart piechartlayout

??????

<Com.openxu.cview.chart.piechart.PieChartLayoutAndroid:id="@+id/piechart1"Android:layout_width="Match_parent"android:layout_height="180DP"Android:layout_centervertical="True"android:paddingright="10DP"Android:background="#ffffff"android:orientation="Horizontal" ><com.openxu.cview.chart.piechart.piechart android:layout_width=" match_parent " Android:layout_height= "match_parent" android:layout_ Weight= "1"/> < Com.openxu.cview.chart.piechart.PieChartLableView android:layout_width= "match_parent" android:layout_height= Match_ Parent "android:layout_weight=" 2 "/> </COM.OPENXU.CVIEW.CHART.PIECHART.PIECHARTLAYOUT>   
Piechartlayout PieChart1 = (piechartlayout) Findviewbyid (R. ID. PieChart1);/* * Ring Width * ringwidth > 0: Hollow Ring, inner ring is white, can be drawn in inner ring * ringwidth <=0: Solid */piechart1. Setringwidth (Densityutil. dip2px (This,15));p IeChart1. Setlinelenth (Densityutil. dip2px (This,8)); Indicator line Length PieChart1. Settagmodul (Piechartlayout. Tag_modul. Modul_chart); Show TagpieChart1 on a fan chart. Setdebug (False);p IeChart1. Setloading (True);//Request data list<piechartbean> DataList = new Arraylist<> ();d atalist. Add (New Piechartbean (20,"Barber Shop"));d atalist. Add (New Piechartbean (20,"KTV"));//displayed in the middle of the lablelist<chartlable> tablelist = new Arraylist<> (); tablelist. Add (New Chartlable ("Architecture", densityutil. sp2px (This,(), Getresources (). GetColor (R. Color. Text_color_light_gray))); tablelist.add (New chartlable (.sp2px (this, 12), Getresources () .color.text_color_light_gray))) ;p iechart1.setloading (false) ;/ /parameter  1: Data type parameter  2: Quantity field Name parameter  3: Name field parameter Span class= "Hljs-number" > 4: Data collection parameters 5:lable collection Piechart1.class,  "Numner",  "Name", DataList, Tablelist)        

3, Progress ring diagram Progresspiechart

??????

<com.openxu.cview.chart.ProgressPieChart    android:id="@+id/chart1"    android:layout_width="120dp" android:layout_height="120dp" android:background="#ffffff"/>
Progresspiechart Chart1 = (progresspiechart) Findviewbyid (R. ID. Chart1); Chart1. Setprosize (Densityutil. dip2px (This,5)); Ring width Chart1. Setdebug (False); Chart1. Setloading (False); Chart1. Setprocolor (Color. Parsecolor ("#ff0000")); Progress color//Ring middle display lablelist<chartlable> lables = new Arraylist<> ();lables.add (New Chartlable (  "60.0%", Densityutil.sp2px (This, 12), Color.parsecolor ( "# ff0000 ")) ;lables.add (New chartlable (" completion rate, Densityutil.sp2px (this, 8), Getresources () .getcolor (R.color.text_color_light_gray)") ;chart1 . SetData (100, 60, lables)    
4, longitudinal column chart Barverticalchart

??????

<com.openxu.cview.chart.barchart.BarVerticalChart    android:id="@+id/chart1"    android:layout_width="match_parent" android:layout_height="250dip" android:background="#ffffff" android:padding="10dp"/>

Barverticalchart Chart1 = (barverticalchart) Findviewbyid (R.ID.CHART1); Chart1.setbarspace (This,1));Double column Spacing Chart1.setbaritemspace (densityutil.dip2px (This,20));Column Spacing Chart1.setdebug (FALSE); Chart1.setbarnum (2);A group of pillars Chart1.setbarcolor (New Int[]{color.parsecolor ("#5F93E7"), Color.parsecolor ("#F28D02")});X-AxisList<string> strxlist =New Arraylist<> ();Column chart datalist<List<barbean>> dataList =New Arraylist<> ();for (int i = 0; I<5; i++) {//this collection is a histogram of data, the collection contains several entities is a few pillars list<barbean> list = new arraylist<> (www.078881.cn  ); list.add (new Barbean (Random.nextint ( 30),  "access System"); list.add (new Barbean (Random.nextint ( 20),  "audit Information"); Datalist.add (list) Strxlist.add ((I+1) + false); Chart1.setdata (DataList, strxlist);     

5, transverse column chart Barhorizontalchart

??????

<com.openxu.cview.chart.barchart.BarHorizontalChart    android:id="@+id/chart1"    android:layout_width="match_parent" android:layout_height="250dp" android:layout_marginTop="20dp" android:background="#ffffff" android:padding="10dip"/>
Barhorizontalchart Chart1 = (barhorizontalchart) Findviewbyid (R.ID.CHART1); Chart1.setbarspace (DensityUtil.dip2px ( This, www.mcyllpt.com/1));Double column Spacing Chart1.setbaritemspace (densityutil.dip2px (This,20));Column Spacing Chart1.setdebug (FALSE); Chart1.setbarnum (3); Chart1.setbarcolor (New Int[]{color.parsecolor ("#5F93E7"), Color.parsecolor ("#F28D02")});X-AxisList<string> strxlist =New Arraylist<> (www.leyou2.net);Column chart datalist<List<barbean>> dataList =New Arraylist<> ();for (int i =0; I<100; i++) {//This collection is a piece of data on a histogram, The collection contains several entities that are several pillars list<barbean> list = new arraylist<> (www.leyouzaixian2.com); list.add (new Barbean (Random.nextint ( 30),  "Lable1"); list.add (new Barbean (Random.nextint ( www.yongshiyule178.com 0),  "Lable2"); Datalist.add (list) Strxlist.add ((I+1) + false); Chart1.setdata (DataList, www.hjha178.com/strXList);   

Open Source an Android custom chart library

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.