2424import com .github .mikephil .charting .components .Legend .LegendForm ;
2525import com .github .mikephil .charting .components .LimitLine ;
2626import com .github .mikephil .charting .components .LimitLine .LimitLabelPosition ;
27- import com .github .mikephil .charting .components .XAxis ;
28- import com .github .mikephil .charting .components .YAxis ;
2927import com .github .mikephil .charting .data .Entry ;
3028import com .github .mikephil .charting .data .LineData ;
3129import com .github .mikephil .charting .data .LineDataSet ;
@@ -89,24 +87,18 @@ protected void onCreate(Bundle savedInstanceState) {
8987 // force pinch zoom along both axis
9088 binding .chart1 .setPinchZoom (true );
9189
92- XAxis xAxis ;
93- xAxis = binding .chart1 .getXAxis ();
94-
9590 // vertical grid lines
96- xAxis .enableGridDashedLine (10f , 10f , 0f );
97-
98- YAxis yAxis ;
99- yAxis = binding .chart1 .getAxisLeft ();
91+ binding .chart1 .getXAxis ().enableGridDashedLine (10f , 10f , 0f );
10092
10193 // disable dual axis (only use LEFT axis)
10294 binding .chart1 .getAxisRight ().setEnabled (false );
10395
10496 // horizontal grid lines
105- yAxis .enableGridDashedLine (10f , 10f , 0f );
97+ binding . chart1 . getAxisLeft () .enableGridDashedLine (10f , 10f , 0f );
10698
10799 // axis range
108- yAxis .setAxisMaximum (200f );
109- yAxis .setAxisMinimum (-50f );
100+ binding . chart1 . getAxisLeft () .setAxisMaximum (200f );
101+ binding . chart1 . getAxisLeft () .setAxisMinimum (-50f );
110102
111103 LimitLine llXAxis = new LimitLine (9f , "Index 10" );
112104 llXAxis .setLineWidth (4f );
@@ -115,27 +107,27 @@ protected void onCreate(Bundle savedInstanceState) {
115107 llXAxis .setTextSize (10f );
116108 llXAxis .setTypeface (tfRegular );
117109
118- LimitLine ll1 = new LimitLine (150f , "Upper Limit" );
119- ll1 .setLineWidth (4f );
120- ll1 .enableDashedLine (10f , 10f , 0f );
121- ll1 .setLabelPosition (LimitLabelPosition .RIGHT_TOP );
122- ll1 .setTextSize (10f );
123- ll1 .setTypeface (tfRegular );
110+ LimitLine LimitLine1 = new LimitLine (150f , "Upper Limit" );
111+ LimitLine1 .setLineWidth (4f );
112+ LimitLine1 .enableDashedLine (10f , 10f , 0f );
113+ LimitLine1 .setLabelPosition (LimitLabelPosition .RIGHT_TOP );
114+ LimitLine1 .setTextSize (10f );
115+ LimitLine1 .setTypeface (tfRegular );
124116
125- LimitLine ll2 = new LimitLine (-30f , "Lower Limit" );
126- ll2 .setLineWidth (4f );
127- ll2 .enableDashedLine (10f , 10f , 0f );
128- ll2 .setLabelPosition (LimitLabelPosition .RIGHT_BOTTOM );
129- ll2 .setTextSize (10f );
130- ll2 .setTypeface (tfRegular );
117+ LimitLine LimitLine2 = new LimitLine (-30f , "Lower Limit" );
118+ LimitLine2 .setLineWidth (4f );
119+ LimitLine2 .enableDashedLine (10f , 10f , 0f );
120+ LimitLine2 .setLabelPosition (LimitLabelPosition .RIGHT_BOTTOM );
121+ LimitLine2 .setTextSize (10f );
122+ LimitLine2 .setTypeface (tfRegular );
131123
132124 // draw limit lines behind data instead of on top
133- yAxis .setDrawLimitLinesBehindData (true );
134- xAxis .setDrawLimitLinesBehindData (true );
125+ binding . chart1 . getAxisLeft () .setDrawLimitLinesBehindData (true );
126+ binding . chart1 . getXAxis () .setDrawLimitLinesBehindData (true );
135127
136128 // add limit lines
137- yAxis . addLimitLine (ll1 );
138- yAxis . addLimitLine (ll2 );
129+ binding . chart1 . getAxisLeft (). addLimitLine (LimitLine1 );
130+ binding . chart1 . getAxisLeft (). addLimitLine (LimitLine2 );
139131 //xAxis.addLimitLine(llXAxis);
140132
141133 // add data
@@ -147,10 +139,8 @@ protected void onCreate(Bundle savedInstanceState) {
147139 binding .chart1 .animateX (1500 );
148140
149141 // get the legend (only possible after setting data)
150- Legend l = binding .chart1 .getLegend ();
151-
152- // draw legend entries as lines
153- l .setForm (LegendForm .LINE );
142+ Legend legend = binding .chart1 .getLegend ();
143+ legend .setForm (LegendForm .LINE );
154144 }
155145
156146 private void setData (int count , float range ) {
@@ -245,18 +235,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
245235 List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
246236
247237 for (ILineDataSet iSet : sets ) {
248-
249238 LineDataSet set = (LineDataSet ) iSet ;
250239 set .setDrawValues (!set .isDrawValuesEnabled ());
251240 }
252-
253241 binding .chart1 .invalidate ();
254242 }
255243 case R .id .actionToggleIcons -> {
256244 List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
257245
258246 for (ILineDataSet iSet : sets ) {
259-
260247 LineDataSet set = (LineDataSet ) iSet ;
261248 set .setDrawIcons (!set .isDrawIconsEnabled ());
262249 }
@@ -270,11 +257,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
270257 }
271258 }
272259 case R .id .actionToggleFilled -> {
273-
274260 List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
275261
276262 for (ILineDataSet iSet : sets ) {
277-
278263 LineDataSet set = (LineDataSet ) iSet ;
279264 set .setDrawFilled (!set .isDrawFilledEnabled ());
280265 }
@@ -284,7 +269,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
284269 List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
285270
286271 for (ILineDataSet iSet : sets ) {
287-
288272 LineDataSet set = (LineDataSet ) iSet ;
289273 set .setDrawCircles (!set .isDrawCirclesEnabled ());
290274 }
@@ -294,7 +278,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
294278 List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
295279
296280 for (ILineDataSet iSet : sets ) {
297-
298281 LineDataSet set = (LineDataSet ) iSet ;
299282 set .setMode (set .getMode () == LineDataSet .Mode .CUBIC_BEZIER ? LineDataSet .Mode .LINEAR : LineDataSet .Mode .CUBIC_BEZIER );
300283 }
@@ -304,7 +287,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
304287 List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
305288
306289 for (ILineDataSet iSet : sets ) {
307-
308290 LineDataSet set = (LineDataSet ) iSet ;
309291 set .setMode (set .getMode () == LineDataSet .Mode .STEPPED ? LineDataSet .Mode .LINEAR : LineDataSet .Mode .STEPPED );
310292 }
@@ -314,15 +296,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
314296 List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
315297
316298 for (ILineDataSet iSet : sets ) {
317-
318299 LineDataSet set = (LineDataSet ) iSet ;
319300 set .setMode (set .getMode () == LineDataSet .Mode .HORIZONTAL_BEZIER ? LineDataSet .Mode .LINEAR : LineDataSet .Mode .HORIZONTAL_BEZIER );
320301 }
321302 binding .chart1 .invalidate ();
322303 }
323304 case R .id .actionTogglePinch -> {
324305 binding .chart1 .setPinchZoom (!binding .chart1 .isPinchZoomEnabled ());
325-
326306 binding .chart1 .invalidate ();
327307 }
328308 case R .id .actionToggleAutoScaleMinMax -> {
0 commit comments