?遇到一个比较奇葩的需求,需要为PieChart添加网格线。虽然众所周知饼图是没有X、Y轴的,而网格线是和轴线一起衍生出来的,但有时候就是会遇到这样的设计?。
? ?我最开始的思路是为PieChart添加轴线,让饼图实现轴线对应的方法,从而获取预期?的网格线。但是看了一下LineChart对应轴线部分的代码后,感觉越高越复杂?,放弃了。
? ?换了种思路,网格线不直接做到PieChart里去了,把PieChart放到一个FrameLayout里,然后用View直接画直线作为网格线?。只要不能缩放,且网格线数量不多,这种方式是最省时省力的?选择。布局部分的代码如下?:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_below="@id/tv_title"
android:layout_marginTop="10dp">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black"
android:layout_marginTop="100dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/black"
android:layout_marginTop="200dp"/>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pc_pie_chart"
android:layout_width="400dp"
android:layout_height="400dp" />
</FrameLayout>
本文暂时没有评论,来添加一个吧(●'◡'●)