22package com .xxmassdeveloper .mpchartexample ;
33
44import android .os .Bundle ;
5+ import android .util .Log ;
56import android .view .Menu ;
67import android .view .MenuItem ;
78import android .view .WindowManager ;
1617import com .github .mikephil .charting .data .Entry ;
1718import com .github .mikephil .charting .data .filter .Approximator ;
1819import com .github .mikephil .charting .data .filter .Approximator .ApproximatorType ;
20+ import com .github .mikephil .charting .interfaces .OnChartValueSelectedListener ;
1921import com .github .mikephil .charting .utils .ColorTemplate ;
22+ import com .github .mikephil .charting .utils .Highlight ;
2023import com .github .mikephil .charting .utils .Legend ;
2124import com .github .mikephil .charting .utils .Legend .LegendPosition ;
2225import com .github .mikephil .charting .utils .XLabels ;
2730
2831import java .util .ArrayList ;
2932
30- public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListener {
33+ public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListener ,
34+ OnChartValueSelectedListener {
3135
3236 private BarChart mChart ;
3337 private SeekBar mSeekBarX , mSeekBarY ;
@@ -50,6 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
5054 mSeekBarY .setOnSeekBarChangeListener (this );
5155
5256 mChart = (BarChart ) findViewById (R .id .chart1 );
57+ mChart .setOnChartValueSelectedListener (this );
5358
5459 // enable the drawing of values
5560 mChart .setDrawYValues (true );
@@ -70,8 +75,6 @@ protected void onCreate(Bundle savedInstanceState) {
7075 // scaling can now only be done on x- and y-axis separately
7176 mChart .setPinchZoom (false );
7277
73- mChart .setUnit (" €" );
74-
7578 mChart .setDrawBarShadow (false );
7679
7780 // change the position of the y-labels
@@ -207,20 +210,25 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
207210 ArrayList <Entry > yVals1 = new ArrayList <Entry >();
208211
209212 for (int i = 0 ; i < mSeekBarX .getProgress (); i ++) {
210- float mult = (mSeekBarY .getProgress () + 1 );
213+ float mult = (mSeekBarY .getProgress () + 1 ) * 1000 ;
211214 float val1 = (float ) (Math .random () * mult ) + mult / 3 ;
212215 float val2 = (float ) (Math .random () * mult ) + mult / 3 ;
213216 float val3 = (float ) (Math .random () * mult ) + mult / 3 ;
214-
215- yVals1 .add (new Entry (new float [] { val1 , val2 , val3 }, i ));
217+
218+ yVals1 .add (new Entry (new float [] {
219+ val1 , val2 , val3
220+ }, i ));
216221 }
217222
218- BarDataSet set1 = new BarDataSet (yVals1 , "DataSet" );
219- set1 .setColors (ColorTemplate .createColors (getApplicationContext (), ColorTemplate .VORDIPLOM_COLORS ));
220-
223+ BarDataSet set1 = new BarDataSet (yVals1 , "Statistics Europe 2014" );
224+ set1 .setColors (ColorTemplate .createColors (getApplicationContext (),
225+ ColorTemplate .VORDIPLOM_COLORS ));
226+ set1 .setStackLabels (new String [] {
227+ "Births" , "Divorces" , "Marriages"
228+ });
229+
221230 ArrayList <BarDataSet > dataSets = new ArrayList <BarDataSet >();
222231 dataSets .add (set1 );
223-
224232
225233 BarData data = new BarData (xVals , dataSets );
226234
@@ -239,4 +247,17 @@ public void onStopTrackingTouch(SeekBar seekBar) {
239247 // TODO Auto-generated method stub
240248
241249 }
250+
251+ @ Override
252+ public void onValuesSelected (Entry [] values , Highlight [] highlights ) {
253+
254+ Log .i ("VALUE SELECTED" ,
255+ values [0 ].toString () + ", dataSet: " + highlights [0 ].getDataSetIndex ());
256+ }
257+
258+ @ Override
259+ public void onNothingSelected () {
260+ // TODO Auto-generated method stub
261+
262+ }
242263}
0 commit comments