開源一個Android自訂圖表庫

來源:互聯網
上載者:User

標籤:完成   chm   pre   space   font   樣本   MTA   get   AC   

    • 類庫接入
    • 使用樣本
      • 1、南丁格爾玫瑰圖 NightingaleRoseChart
      • 2、佔比餅狀圖表 PieChartLayout
      • 3、進度環形圖 ProgressPieChart
      • 4、縱向柱狀圖 BarVerticalChart
      • 5、橫向柱狀圖 BarHorizontalChart
    • 源碼下載

 

??項目中有一些圖表需求,一開始嘗試使用一些開源的圖表庫,這些圖表庫功能很強大,圖表種類應有盡有,是不錯的選擇。但是這些類庫使用起來通常需要大量的設定,對於項目風格不能很好的貼合。於是自己嘗試寫了一個圖表庫,使用起來非常方便,注釋清晰,後期擴充性強。

類庫接入

build.gradle中添加依賴:

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

其中<new version>替換為最新版本,版本查看OXChart

使用樣本1、南丁格爾玫瑰圖 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);    //是否在圖表上顯示指示lableroseChartSmall.setShowChartNum(false);     //是否在圖表上顯示指示numroseChartSmall.setShowNumTouched(false);   //點擊顯示數量roseChartSmall.setShowRightNum(true);      //右側顯示數量roseList.add(new RoseBean(10, "資料1"));roseList.add(new RoseBean(13, "資料2"));roseList.add(new RoseBean(31, "資料3"));roseList.add(new RoseBean(8, "資料4"));roseList.add(new RoseBean(21, "資料5"));//參數1:資料對象class, 參數2:數量屬性欄位名稱, 參數3:名稱屬性欄位名稱, 參數4:資料集合roseChartSmall.setData(RoseBean.class, "count", "ClassName", roseList);roseChartSmall.setLoading(false);//是否正在載入,資料載入完畢後置為false
2、佔比餅狀圖表 PieChartLayout

??????

<com.openxu.cview.chart.piechart.PieChartLayout   android: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);/* * 圓環寬度 * ringWidth > 0 :空心圓環,內環為白色,可以在內環中繪製字 * ringWidth <=0 :實心 */pieChart1.setRingWidth(DensityUtil.dip2px(this, 15));pieChart1.setLineLenth(DensityUtil.dip2px(this, 8)); // //指示線長度pieChart1.setTagModul(PieChartLayout.TAG_MODUL.MODUL_CHART);       //在扇形圖上顯示tagpieChart1.setDebug(false);pieChart1.setLoading(true);//請求資料List<PieChartBean> datalist = new ArrayList<>();datalist.add(new PieChartBean(20, "理髮屋"));datalist.add(new PieChartBean(20, "KTV"));//顯示在中間的lableList<ChartLable> tableList = new ArrayList<>();tableList.add(new ChartLable("建築", DensityUtil.sp2px(this, 12), getResources().getColor(R.color.text_color_light_gray)));tableList.add(new ChartLable("性質", DensityUtil.sp2px(this, 12), getResources().getColor(R.color.text_color_light_gray)));pieChart1.setLoading(false);//參數1:資料類型   參數2:數量欄位名稱   參數3:名稱欄位   參數4:資料集合   參數5:lable集合pieChart1.setChartData(PieChartBean.class, "Numner", "Name",datalist ,tableList);

 

3、進度環形圖 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));  //圓環寬度chart1.setDebug(false);chart1.setLoading(false);chart1.setProColor(Color.parseColor("#ff0000"));  //進度顏色//環形中間顯示的lableList<ChartLable> lables = new ArrayList<>();lables.add(new ChartLable("60.0%",        DensityUtil.sp2px(this, 12), Color.parseColor("#ff0000")));lables.add(new ChartLable("完成率",        DensityUtil.sp2px(this, 8), getResources().getColor(R.color.text_color_light_gray)));chart1.setData(100, 60, lables);
4、縱向柱狀圖 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(DensityUtil.dip2px(this, 1));  //雙柱間距chart1.setBarItemSpace(DensityUtil.dip2px(this, 20));  //柱間距chart1.setDebug(false);chart1.setBarNum(2);   //一組柱子數量chart1.setBarColor(new int[]{Color.parseColor("#5F93E7"),Color.parseColor("#F28D02")});//X軸List<String> strXList = new ArrayList<>();//柱狀圖資料List<List<BarBean>> dataList = new ArrayList<>();for(int i = 0; i<5; i++){    //此集合為柱狀圖上一條資料,集合中包含幾個實體就是幾個柱子    List<BarBean> list = new ArrayList<>(www.078881.cn  );    list.add(new BarBean(random.nextInt(30), "接入系統"));    list.add(new BarBean(random.nextInt(20), "審核資訊"));    dataList.add(list);    strXList.add((i+1)+"月");}chart1.setLoading(false);chart1.setData(dataList, strXList);

 

5、橫向柱狀圖 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));  //雙柱間距chart1.setBarItemSpace(DensityUtil.dip2px(this, 20));  //柱間距chart1.setDebug(false);chart1.setBarNum(3);chart1.setBarColor(new int[]{Color.parseColor("#5F93E7"),Color.parseColor("#F28D02")});//X軸List<String> strXList = new ArrayList<>(www.leyou2.net);//柱狀圖資料List<List<BarBean>> dataList = new ArrayList<>();for(int i = 0; i<100; i++){    //此集合為柱狀圖上一條資料,集合中包含幾個實體就是幾個柱子    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)+"月");}chart1.setLoading(false);chart1.setData(dataList, www.hjha178.com/ strXList);

開源一個Android自訂圖表庫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.