1717import com .github .mikephil .charting .components .Legend .LegendForm ;
1818import com .github .mikephil .charting .components .Legend .LegendPosition ;
1919import com .github .mikephil .charting .components .XAxis ;
20- import com .github .mikephil .charting .components .XAxis .XAxisPosition ;
2120import com .github .mikephil .charting .components .YAxis ;
2221import com .github .mikephil .charting .data .BarData ;
2322import com .github .mikephil .charting .data .BarDataSet ;
2423import com .github .mikephil .charting .data .BarEntry ;
2524import com .github .mikephil .charting .data .XAxisValue ;
26- import com .github .mikephil .charting .data .filter .Approximator ;
27- import com .github .mikephil .charting .data .filter .Approximator .ApproximatorType ;
2825import com .github .mikephil .charting .interfaces .datasets .IBarDataSet ;
2926import com .github .mikephil .charting .utils .FileUtils ;
3027import com .xxmassdeveloper .mpchartexample .notimportant .DemoBase ;
@@ -37,9 +34,9 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
3734 protected BarChart mChart ;
3835 private SeekBar mSeekBarX ;
3936 private TextView tvX ;
40-
37+
4138 private Typeface mTf ;
42-
39+
4340 private List <BarEntry > mSinusData ;
4441
4542 @ Override
@@ -48,8 +45,8 @@ protected void onCreate(Bundle savedInstanceState) {
4845 getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN ,
4946 WindowManager .LayoutParams .FLAG_FULLSCREEN );
5047 setContentView (R .layout .activity_barchart_sinus );
51-
52- mSinusData = FileUtils .loadBarEntriesFromAssets (getAssets (),"othersine.txt" );
48+
49+ mSinusData = FileUtils .loadBarEntriesFromAssets (getAssets (), "othersine.txt" );
5350
5451 tvX = (TextView ) findViewById (R .id .tvValueCount );
5552
@@ -129,7 +126,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
129126 break ;
130127 }
131128 case R .id .actionToggleHighlight : {
132- if (mChart .getData () != null ) {
129+ if (mChart .getData () != null ) {
133130 mChart .getData ().setHighlightEnabled (!mChart .getData ().isHighlightEnabled ());
134131 mChart .invalidate ();
135132 }
@@ -149,6 +146,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
149146 mChart .notifyDataSetChanged ();
150147 break ;
151148 }
149+ case R .id .actionToggleBarBorders : {
150+ for (IBarDataSet set : mChart .getData ().getDataSets ())
151+ ((BarDataSet ) set ).setBarBorderWidth (set .getBarBorderWidth () == 1.f ? 0.f : 1.f );
152+
153+ mChart .invalidate ();
154+ break ;
155+ }
152156 case R .id .actionToggleHighlightArrow : {
153157 if (mChart .isDrawHighlightArrowEnabled ())
154158 mChart .setDrawHighlightArrow (false );
@@ -206,17 +210,28 @@ public void onStopTrackingTouch(SeekBar seekBar) {
206210
207211 private void setData (int count ) {
208212
213+ List <XAxisValue > xVals = new ArrayList <XAxisValue >();
209214 ArrayList <BarEntry > entries = new ArrayList <BarEntry >();
210-
215+
211216 for (int i = 0 ; i < count ; i ++) {
212217 entries .add (mSinusData .get (i ));
218+ xVals .add (new XAxisValue (i , i +"" ));
219+ }
220+
221+ BarDataSet set ;
222+
223+ if (mChart .getData () != null &&
224+ mChart .getData ().getDataSetCount () > 0 ) {
225+ set = (BarDataSet ) mChart .getData ().getDataSetByIndex (0 );
226+ set .setYVals (entries );
227+ mChart .notifyDataSetChanged ();
228+ } else {
229+ set = new BarDataSet (entries , "Sinus Function" );
230+ set .setBarSpacePercent (40f );
231+ set .setColor (Color .rgb (240 , 120 , 124 ));
213232 }
214-
215- BarDataSet set = new BarDataSet (entries , "Sinus Function" );
216- set .setBarSpacePercent (40f );
217- set .setColor (Color .rgb (240 , 120 , 124 ));
218233
219- BarData data = new BarData (set );
234+ BarData data = new BarData (xVals , set );
220235 data .setValueTextSize (10f );
221236 data .setValueTypeface (mTf );
222237 data .setDrawValues (false );
0 commit comments