1111import android .widget .Toast ;
1212
1313import com .github .mikephil .charting .charts .BarChart ;
14+ import com .github .mikephil .charting .components .XAxis ;
15+ import com .github .mikephil .charting .components .XAxis .XLabelPosition ;
1416import com .github .mikephil .charting .data .BarData ;
1517import com .github .mikephil .charting .data .BarDataSet ;
1618import com .github .mikephil .charting .data .BarEntry ;
19+ import com .github .mikephil .charting .data .DataSet ;
1720import com .github .mikephil .charting .data .filter .Approximator ;
1821import com .github .mikephil .charting .data .filter .Approximator .ApproximatorType ;
1922import com .github .mikephil .charting .utils .ColorTemplate ;
20- import com .github .mikephil .charting .utils .XLabels ;
21- import com .github .mikephil .charting .utils .XLabels .XLabelPosition ;
2223import com .xxmassdeveloper .mpchartexample .notimportant .DemoBase ;
2324
2425import java .util .ArrayList ;
@@ -46,49 +47,41 @@ protected void onCreate(Bundle savedInstanceState) {
4647 mSeekBarY .setOnSeekBarChangeListener (this );
4748
4849 mChart = (BarChart ) findViewById (R .id .chart1 );
49-
50- mChart .setDrawYValues (false );
5150
52- mChart .setUnit (" €" );
5351 mChart .setDescription ("" );
54-
55- mChart .setDrawYValues (true );
5652
5753 // if more than 60 entries are displayed in the chart, no values will be
5854 // drawn
5955 mChart .setMaxVisibleValueCount (60 );
6056
61- // disable 3D
62- mChart .set3DEnabled (false );
6357 // scaling can now only be done on x- and y-axis separately
6458 mChart .setPinchZoom (false );
6559
6660 mChart .setDrawBarShadow (false );
67-
61+
6862 mChart .setDrawVerticalGrid (false );
6963 mChart .setDrawHorizontalGrid (false );
7064 mChart .setDrawGridBackground (false );
7165
72- XLabels xLabels = mChart .getXLabels ();
73- xLabels .setPosition (XLabelPosition .BOTTOM );
74- xLabels .setCenterXLabelText (true );
75- xLabels .setSpaceBetweenLabels (0 );
66+ XAxis xAxis = mChart .getXAxis ();
67+ xAxis .setPosition (XLabelPosition .BOTTOM );
68+ xAxis .setCenterXLabelText (true );
69+ xAxis .setSpaceBetweenLabels (0 );
7670
77- mChart .setDrawYLabels (false );
78- mChart .setDrawLegend (false );
71+ mChart .setDrawLegend (false );
7972
8073 // setting data
8174 mSeekBarX .setProgress (10 );
8275 mSeekBarY .setProgress (100 );
83-
76+
8477 // add a nice and smooth animation
8578 mChart .animateY (2500 );
8679
87- // Legend l = mChart.getLegend();
88- // l.setPosition(LegendPosition.BELOW_CHART_CENTER);
89- // l.setFormSize(8f);
90- // l.setFormToTextSpace(4f);
91- // l.setXEntrySpace(6f);
80+ // Legend l = mChart.getLegend();
81+ // l.setPosition(LegendPosition.BELOW_CHART_CENTER);
82+ // l.setFormSize(8f);
83+ // l.setFormToTextSpace(4f);
84+ // l.setXEntrySpace(6f);
9285
9386 // mChart.setDrawLegend(false);
9487 }
@@ -104,18 +97,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
10497
10598 switch (item .getItemId ()) {
10699 case R .id .actionToggleValues : {
107- if (mChart .isDrawYValuesEnabled ())
108- mChart .setDrawYValues (false );
109- else
110- mChart .setDrawYValues (true );
111- mChart .invalidate ();
112- break ;
113- }
114- case R .id .actionToggle3D : {
115- if (mChart .is3DEnabled ())
116- mChart .set3DEnabled (false );
117- else
118- mChart .set3DEnabled (true );
100+
101+ for (DataSet <?> set : mChart .getData ().getDataSets ())
102+ set .setDrawValues (!set .isDrawValuesEnabled ());
103+
119104 mChart .invalidate ();
120105 break ;
121106 }
@@ -154,12 +139,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
154139 break ;
155140 }
156141 case R .id .actionToggleAdjustXLegend : {
157- XLabels xLabels = mChart .getXLabels ();
142+ XAxis xAxis = mChart .getXAxis ();
158143
159- if (xLabels .isAdjustXLabelsEnabled ())
160- xLabels .setAdjustXLabels (false );
144+ if (xAxis .isAdjustXLabelsEnabled ())
145+ xAxis .setAdjustXLabels (false );
161146 else
162- xLabels .setAdjustXLabels (true );
147+ xAxis .setAdjustXLabels (true );
163148
164149 mChart .invalidate ();
165150 break ;
@@ -210,19 +195,20 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
210195
211196 ArrayList <BarEntry > yVals1 = new ArrayList <BarEntry >();
212197
213- for (int i = 0 ; i < mSeekBarX .getProgress ()+ 1 ; i ++) {
198+ for (int i = 0 ; i < mSeekBarX .getProgress () + 1 ; i ++) {
214199 float mult = (mSeekBarY .getProgress () + 1 );
215200 float val1 = (float ) (Math .random () * mult ) + mult / 3 ;
216201 yVals1 .add (new BarEntry ((int ) val1 , i ));
217202 }
218-
203+
219204 ArrayList <String > xVals = new ArrayList <String >();
220- for (int i = 0 ; i < mSeekBarX .getProgress ()+ 1 ; i ++) {
221- xVals .add ((int ) yVals1 .get (i ).getVal () + " " + mChart . getUnit () );
205+ for (int i = 0 ; i < mSeekBarX .getProgress () + 1 ; i ++) {
206+ xVals .add ((int ) yVals1 .get (i ).getVal () + "" );
222207 }
223208
224209 BarDataSet set1 = new BarDataSet (yVals1 , "Data Set" );
225210 set1 .setColors (ColorTemplate .VORDIPLOM_COLORS );
211+ set1 .setDrawValues (false );
226212
227213 ArrayList <BarDataSet > dataSets = new ArrayList <BarDataSet >();
228214 dataSets .add (set1 );
0 commit comments