Skip to content

Commit d49c180

Browse files
committed
新注释,新demo
1 parent 838efbd commit d49c180

4 files changed

Lines changed: 123 additions & 24 deletions

File tree

GyRoseChart/src/main/java/com/gaoyu/rosechart/RoseChart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public String getSplitLineColor() {
157157
}
158158

159159
/**
160-
* 设置分割线颜色
160+
* 设置分割线颜色(建议与背景色相同)
161161
*
162162
* @param splitLineColor 分割线颜色
163163
*/

GyRoseChart/src/main/java/com/gaoyu/rosechart/RoseChartData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class RoseChartData {
2424

2525
/**
2626
* 区块的半径(从圆心到扇形边缘)
27+
* 如果把输入的数据都设成相同的值,就能变成饼图
2728
*/
2829
private float radius;
2930

app/src/main/java/com/Gaoyu/gyviewlibrary/MainActivity.java

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,78 @@ public class MainActivity extends AppCompatActivity {
2020
private RoseChart mChart;
2121
private Button mBtnChange;
2222
private Button mBtnEmpty;
23+
private Button mBtnChart;
24+
private Button mBtnHole;
2325
private TextView mTvItem;
2426

27+
private boolean isRose = true;
28+
private boolean hasHole = true;
29+
30+
private List<RoseChartData> list;
31+
2532
@Override
2633
protected void onCreate(Bundle savedInstanceState) {
2734
super.onCreate(savedInstanceState);
2835
setContentView(R.layout.activity_main);
2936

3037
mChart = findViewById(R.id.chart);
31-
mBtnChange = findViewById(R.id.btn_chart);
38+
mBtnChange = findViewById(R.id.btn_data);
3239
mBtnEmpty = findViewById(R.id.btn_empty);
40+
mBtnChart = findViewById(R.id.btn_chart);
41+
mBtnHole = findViewById(R.id.btn_hole);
3342
mTvItem = findViewById(R.id.tv_item);
3443

3544
mTvItem.setText("无");
3645

37-
List<RoseChartData> list = new ArrayList<>();
46+
list = new ArrayList<>();
3847
list.add(new RoseChartData(null, 80, "#FF40A9FF", 80f));
3948
list.add(new RoseChartData(null, 120, "#FF73B13B", 170f));
4049
list.add(new RoseChartData(null, 45, "#FFFAAD14", 120f));
4150
list.add(new RoseChartData(null, 97, "#FFEE3E3E", 90f));
4251
list.add(new RoseChartData(null, 83, "#FFBBBBBB", 200f));
4352
mChart.setInsideRadius(50f);
4453
mChart.setData(list);
45-
54+
4655
mBtnChange.setOnClickListener(v -> {
47-
list.clear();
48-
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FF40A9FF", (float) (Math.random() * 200)));
49-
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FF73B13B", (float) (Math.random() * 200)));
50-
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFFAAD14", (float) (Math.random() * 200)));
51-
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFEE3E3E", (float) (Math.random() * 200)));
52-
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFBBBBBB", (float) (Math.random() * 200)));
53-
mChart.setInsideRadius((float) (Math.random() * 100));
56+
if (isRose) {
57+
randomRoseList();
58+
} else {
59+
randomPieList();
60+
}
61+
if (hasHole) {
62+
mChart.setInsideRadius((float) (Math.random() * 100));
63+
} else {
64+
mChart.setInsideRadius(0);
65+
}
66+
mChart.setData(list);
67+
});
68+
69+
mBtnChart.setOnClickListener(v -> {
70+
if (isRose) {
71+
isRose = false;
72+
mBtnChart.setText("玫瑰图");
73+
randomPieList();
74+
} else {
75+
isRose = true;
76+
mBtnChart.setText("饼图");
77+
randomRoseList();
78+
}
5479
mChart.setData(list);
5580
});
5681

82+
mBtnHole.setOnClickListener(v -> {
83+
if (hasHole) {
84+
hasHole = false;
85+
mBtnHole.setText("开启内径");
86+
mChart.setInsideRadius(0);
87+
} else {
88+
hasHole = true;
89+
mBtnHole.setText("关闭内径");
90+
mChart.setInsideRadius((float) (Math.random() * 100));
91+
}
92+
mChart.reDraw();
93+
});
94+
5795
mChart.setOnSelectArcItemListener((position, item) -> {
5896
String builder = "第" +
5997
(position + 1) +
@@ -62,7 +100,7 @@ protected void onCreate(Bundle savedInstanceState) {
62100
"数值:" +
63101
item.getQty();
64102
mTvItem.setText(builder);
65-
if(list.get(position).getOffset() == 0) {
103+
if (list.get(position).getOffset() == 0) {
66104
list.get(position).setOffset(40);
67105
} else {
68106
list.get(position).setOffset(0);
@@ -71,7 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
71109
});
72110

73111
mBtnEmpty.setOnClickListener(v -> {
74-
if(mChart.getSplitLineWidth() == 0) {
112+
if (mChart.getSplitLineWidth() == 0) {
75113
mBtnEmpty.setText("不产生分割线");
76114
mChart.setSplitLineWidth(8);
77115
} else {
@@ -81,4 +119,24 @@ protected void onCreate(Bundle savedInstanceState) {
81119
mChart.reDraw();
82120
});
83121
}
122+
123+
private void randomRoseList() {
124+
list.clear();
125+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FF40A9FF", (float) (Math.random() * 200)));
126+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FF73B13B", (float) (Math.random() * 200)));
127+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFFAAD14", (float) (Math.random() * 200)));
128+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFEE3E3E", (float) (Math.random() * 200)));
129+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFBBBBBB", (float) (Math.random() * 200)));
130+
}
131+
132+
private void randomPieList() {
133+
list.clear();
134+
float radius = (float) (Math.random() * 200);
135+
radius = (radius > 100 ? radius : 100);
136+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FF40A9FF", radius));
137+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FF73B13B", radius));
138+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFFAAD14", radius));
139+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFEE3E3E", radius));
140+
list.add(new RoseChartData(null, (int) (Math.random() * 200), "#FFBBBBBB", radius));
141+
}
84142
}

app/src/main/res/layout/activity_main.xml

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<TextView
1212
android:id="@+id/tv_item"
13-
android:layout_marginTop="20px"
1413
android:layout_width="match_parent"
1514
android:layout_height="wrap_content"
15+
android:layout_marginTop="20px"
1616
android:gravity="center"
1717
android:textColor="@color/black"
1818
android:textSize="50px" />
@@ -23,21 +23,61 @@
2323
android:layout_height="0px"
2424
android:layout_weight="1" />
2525

26-
<Button
27-
android:id="@+id/btn_empty"
26+
<LinearLayout
2827
android:layout_width="match_parent"
2928
android:layout_height="wrap_content"
30-
android:background="@color/black"
31-
android:text="产生分割线"
32-
android:textSize="37px" />
29+
android:orientation="horizontal">
30+
31+
<Button
32+
android:id="@+id/btn_chart"
33+
android:layout_width="0px"
34+
android:layout_height="wrap_content"
35+
android:layout_weight="1"
36+
android:background="@color/black"
37+
android:text="饼图"
38+
android:textSize="37px" />
39+
40+
<View
41+
android:layout_width="20px"
42+
android:layout_height="match_parent"/>
3343

34-
<Button
35-
android:id="@+id/btn_chart"
44+
<Button
45+
android:id="@+id/btn_hole"
46+
android:layout_width="0px"
47+
android:layout_height="wrap_content"
48+
android:layout_weight="1"
49+
android:background="@color/black"
50+
android:text="关闭内径"
51+
android:textSize="37px" />
52+
</LinearLayout>
53+
54+
<LinearLayout
3655
android:layout_width="match_parent"
3756
android:layout_height="wrap_content"
3857
android:layout_marginTop="20px"
39-
android:background="@color/black"
40-
android:text="随机数据"
41-
android:textSize="37px" />
58+
android:orientation="horizontal">
59+
60+
<Button
61+
android:id="@+id/btn_empty"
62+
android:layout_width="0px"
63+
android:layout_height="wrap_content"
64+
android:layout_weight="1"
65+
android:background="@color/black"
66+
android:text="产生分割线"
67+
android:textSize="37px" />
68+
69+
<View
70+
android:layout_width="20px"
71+
android:layout_height="match_parent"/>
72+
73+
<Button
74+
android:id="@+id/btn_data"
75+
android:layout_width="0px"
76+
android:layout_height="wrap_content"
77+
android:layout_weight="1"
78+
android:background="@color/black"
79+
android:text="随机数据"
80+
android:textSize="37px" />
81+
</LinearLayout>
4282

4383
</LinearLayout>

0 commit comments

Comments
 (0)