88import android .view .Menu ;
99import android .view .MenuItem ;
1010import android .view .WindowManager ;
11+ import android .widget .Toast ;
1112
1213import com .github .mikephil .charting .charts .LineChart ;
1314import com .github .mikephil .charting .components .Legend ;
@@ -61,7 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {
6162
6263 LineData data = new LineData ();
6364 data .setValueTextColor (Color .WHITE );
64-
65+
6566 // add empty data
6667 mChart .setData (data );
6768
@@ -87,7 +88,7 @@ protected void onCreate(Bundle savedInstanceState) {
8788 leftAxis .setTextColor (Color .WHITE );
8889 leftAxis .setAxisMaxValue (120f );
8990 leftAxis .setDrawGridLines (true );
90-
91+
9192 YAxis rightAxis = mChart .getAxisRight ();
9293 rightAxis .setEnabled (false );
9394 }
@@ -106,12 +107,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
106107 addEntry ();
107108 break ;
108109 }
110+ case R .id .actionClear : {
111+ mChart .clearValues ();
112+ Toast .makeText (this , "Chart cleared!" , Toast .LENGTH_SHORT ).show ();
113+ break ;
114+ }
109115 }
110116 return true ;
111117 }
112118
113119 private int year = 15 ;
114-
120+
115121 private void addEntry () {
116122
117123 LineData data = mChart .getData ();
@@ -127,24 +133,26 @@ private void addEntry() {
127133 }
128134
129135 // add a new x-value first
130- data .addXValue (mMonths [data .getXValCount () % 12 ] + " " + (year + data .getXValCount () / 12 ));
136+ data .addXValue (mMonths [data .getXValCount () % 12 ] + " "
137+ + (year + data .getXValCount () / 12 ));
131138 data .addEntry (new Entry ((float ) (Math .random () * 40 ) + 40f , set .getEntryCount ()), 0 );
132139
133140 // let the chart know it's data has changed
134141 mChart .notifyDataSetChanged ();
135142
136143 // limit the number of visible entries
137- mChart .setVisibleXRange (6 );
144+ mChart .setVisibleXRange (6 );
138145 // mChart.setVisibleYRange(30, AxisDependency.LEFT);
139-
140- // move to the latest entry
141- mChart .moveViewToX (data .getXValCount ()-7 );
142-
143- // this automatically refreshes the chart (calls invalidate())
144- // mChart.moveViewTo(data.getXValCount()-7, 55f, AxisDependency.LEFT);
146+
147+ // move to the latest entry
148+ mChart .moveViewToX (data .getXValCount () - 7 );
149+
150+ // this automatically refreshes the chart (calls invalidate())
151+ // mChart.moveViewTo(data.getXValCount()-7, 55f,
152+ // AxisDependency.LEFT);
145153
146154 // redraw the chart
147- // mChart.invalidate();
155+ // mChart.invalidate();
148156 }
149157 }
150158
0 commit comments