33
44import android .graphics .Typeface ;
55import android .os .Bundle ;
6+ import android .view .Menu ;
7+ import android .view .MenuItem ;
68import android .view .WindowManager ;
7- import android .widget .SeekBar ;
8- import android .widget .SeekBar .OnSeekBarChangeListener ;
9- import android .widget .TextView ;
9+ import android .widget .Toast ;
1010
1111import com .github .mikephil .charting .charts .RadarChart ;
1212import com .github .mikephil .charting .data .Entry ;
13+ import com .github .mikephil .charting .data .LineDataSet ;
1314import com .github .mikephil .charting .data .RadarData ;
1415import com .github .mikephil .charting .data .RadarDataSet ;
15- import com .github .mikephil .charting .utils .ColorTemplate ;
16+ import com .github .mikephil .charting .data .filter .Approximator ;
17+ import com .github .mikephil .charting .data .filter .Approximator .ApproximatorType ;
1618import com .github .mikephil .charting .utils .Legend ;
1719import com .github .mikephil .charting .utils .Legend .LegendPosition ;
20+ import com .github .mikephil .charting .utils .XLabels ;
1821import com .github .mikephil .charting .utils .YLabels ;
19- import com .github .mikephil .charting .utils .YLabels .YLabelPosition ;
2022import com .xxmassdeveloper .mpchartexample .notimportant .DemoBase ;
2123
2224import java .util .ArrayList ;
@@ -42,12 +44,18 @@ protected void onCreate(Bundle savedInstanceState) {
4244
4345 mChart .setWebLineWidth (2f );
4446 mChart .setWebLineWidthInner (0.75f );
47+ mChart .setWebAlpha (140 );
4548
4649 setData ();
50+
51+ XLabels xl = mChart .getXLabels ();
52+ xl .setTypeface (tf );
53+ xl .setTextSize (9f );
4754
4855 YLabels yl = mChart .getYLabels ();
4956 yl .setTypeface (tf );
5057 yl .setLabelCount (5 );
58+ yl .setTextSize (9f );
5159
5260 // mChart.animateXY(1500, 1500);
5361
@@ -57,6 +65,83 @@ protected void onCreate(Bundle savedInstanceState) {
5765 l .setXEntrySpace (7f );
5866 l .setYEntrySpace (5f );
5967 }
68+
69+ @ Override
70+ public boolean onCreateOptionsMenu (Menu menu ) {
71+ getMenuInflater ().inflate (R .menu .radar , menu );
72+ return true ;
73+ }
74+
75+ @ Override
76+ public boolean onOptionsItemSelected (MenuItem item ) {
77+
78+ switch (item .getItemId ()) {
79+ case R .id .actionToggleValues : {
80+ if (mChart .isDrawYValuesEnabled ())
81+ mChart .setDrawYValues (false );
82+ else
83+ mChart .setDrawYValues (true );
84+ mChart .invalidate ();
85+ break ;
86+ }
87+ case R .id .actionToggleHighlight : {
88+ if (mChart .isHighlightEnabled ())
89+ mChart .setHighlightEnabled (false );
90+ else
91+ mChart .setHighlightEnabled (true );
92+ mChart .invalidate ();
93+ break ;
94+ }
95+ case R .id .actionToggleRotate : {
96+ if (mChart .isRotationEnabled ())
97+ mChart .setRotationEnabled (false );
98+ else
99+ mChart .setRotationEnabled (true );
100+ mChart .invalidate ();
101+ break ;
102+ }
103+ case R .id .actionToggleFilled : {
104+
105+ ArrayList <RadarDataSet > sets = (ArrayList <RadarDataSet >) mChart .getDataCurrent ()
106+ .getDataSets ();
107+
108+ for (RadarDataSet set : sets ) {
109+ if (set .isDrawFilledEnabled ())
110+ set .setDrawFilled (false );
111+ else
112+ set .setDrawFilled (true );
113+ }
114+ mChart .invalidate ();
115+ break ;
116+ }
117+ case R .id .actionSave : {
118+ if (mChart .saveToPath ("title" + System .currentTimeMillis (), "" )) {
119+ Toast .makeText (getApplicationContext (), "Saving SUCCESSFUL!" ,
120+ Toast .LENGTH_SHORT ).show ();
121+ } else
122+ Toast .makeText (getApplicationContext (), "Saving FAILED!" , Toast .LENGTH_SHORT )
123+ .show ();
124+ break ;
125+ }
126+ case R .id .actionToggleXLabels : {
127+ if (mChart .isDrawXLabelsEnabled ())
128+ mChart .setDrawXLabels (false );
129+ else
130+ mChart .setDrawXLabels (true );
131+ mChart .invalidate ();
132+ break ;
133+ }
134+ case R .id .actionToggleYLabels : {
135+ if (mChart .isDrawYLabelsEnabled ())
136+ mChart .setDrawYLabels (false );
137+ else
138+ mChart .setDrawYLabels (true );
139+ mChart .invalidate ();
140+ break ;
141+ }
142+ }
143+ return true ;
144+ }
60145
61146 private String [] mParties = new String [] {
62147 "Party A" , "Party B" , "Party C" , "Party D" , "Party E" , "Party F"
@@ -65,34 +150,35 @@ protected void onCreate(Bundle savedInstanceState) {
65150 public void setData () {
66151
67152 float mult = 150 ;
153+ int cnt = 9 ;
68154
69155 ArrayList <Entry > yVals1 = new ArrayList <Entry >();
70156 ArrayList <Entry > yVals2 = new ArrayList <Entry >();
71157
72158 // IMPORTANT: In a PieChart, no values (Entry) should have the same
73159 // xIndex (even if from different DataSets), since no values can be
74160 // drawn above each other.
75- for (int i = 0 ; i < 6 ; i ++) {
161+ for (int i = 0 ; i < cnt ; i ++) {
76162 yVals1 .add (new Entry ((float ) (Math .random () * mult ) + mult / 2 , i ));
77163 }
78164
79- for (int i = 0 ; i < 6 ; i ++) {
165+ for (int i = 0 ; i < cnt ; i ++) {
80166 yVals2 .add (new Entry ((float ) (Math .random () * mult ) + mult / 2 , i ));
81167 }
82168
83169 ArrayList <String > xVals = new ArrayList <String >();
84170
85- for (int i = 0 ; i < 6 ; i ++)
171+ for (int i = 0 ; i < cnt ; i ++)
86172 xVals .add (mParties [i % mParties .length ]);
87173
88174 RadarDataSet set1 = new RadarDataSet (yVals1 , "Set 1" );
89175 set1 .setColor (getResources ().getColor (R .color .vordiplom_1 ));
90- // set1.setDrawFilled(true);
176+ set1 .setDrawFilled (true );
91177 set1 .setLineWidth (2f );
92178
93179 RadarDataSet set2 = new RadarDataSet (yVals2 , "Set 2" );
94180 set2 .setColor (getResources ().getColor (R .color .vordiplom_5 ));
95- // set2.setDrawFilled(true);
181+ set2 .setDrawFilled (true );
96182 set2 .setLineWidth (2f );
97183
98184 ArrayList <RadarDataSet > sets = new ArrayList <RadarDataSet >();
0 commit comments