@@ -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}
0 commit comments