24
24
import com .github .mikephil .charting .components .Legend .LegendForm ;
25
25
import com .github .mikephil .charting .components .LimitLine ;
26
26
import com .github .mikephil .charting .components .LimitLine .LimitLabelPosition ;
27
- import com .github .mikephil .charting .components .XAxis ;
28
- import com .github .mikephil .charting .components .YAxis ;
29
27
import com .github .mikephil .charting .data .Entry ;
30
28
import com .github .mikephil .charting .data .LineData ;
31
29
import com .github .mikephil .charting .data .LineDataSet ;
@@ -89,24 +87,18 @@ protected void onCreate(Bundle savedInstanceState) {
89
87
// force pinch zoom along both axis
90
88
binding .chart1 .setPinchZoom (true );
91
89
92
- XAxis xAxis ;
93
- xAxis = binding .chart1 .getXAxis ();
94
-
95
90
// 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 );
100
92
101
93
// disable dual axis (only use LEFT axis)
102
94
binding .chart1 .getAxisRight ().setEnabled (false );
103
95
104
96
// horizontal grid lines
105
- yAxis .enableGridDashedLine (10f , 10f , 0f );
97
+ binding . chart1 . getAxisLeft () .enableGridDashedLine (10f , 10f , 0f );
106
98
107
99
// axis range
108
- yAxis .setAxisMaximum (200f );
109
- yAxis .setAxisMinimum (-50f );
100
+ binding . chart1 . getAxisLeft () .setAxisMaximum (200f );
101
+ binding . chart1 . getAxisLeft () .setAxisMinimum (-50f );
110
102
111
103
LimitLine llXAxis = new LimitLine (9f , "Index 10" );
112
104
llXAxis .setLineWidth (4f );
@@ -115,27 +107,27 @@ protected void onCreate(Bundle savedInstanceState) {
115
107
llXAxis .setTextSize (10f );
116
108
llXAxis .setTypeface (tfRegular );
117
109
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 );
124
116
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 );
131
123
132
124
// 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 );
135
127
136
128
// add limit lines
137
- yAxis . addLimitLine (ll1 );
138
- yAxis . addLimitLine (ll2 );
129
+ binding . chart1 . getAxisLeft (). addLimitLine (LimitLine1 );
130
+ binding . chart1 . getAxisLeft (). addLimitLine (LimitLine2 );
139
131
//xAxis.addLimitLine(llXAxis);
140
132
141
133
// add data
@@ -147,10 +139,8 @@ protected void onCreate(Bundle savedInstanceState) {
147
139
binding .chart1 .animateX (1500 );
148
140
149
141
// 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 );
154
144
}
155
145
156
146
private void setData (int count , float range ) {
@@ -245,18 +235,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
245
235
List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
246
236
247
237
for (ILineDataSet iSet : sets ) {
248
-
249
238
LineDataSet set = (LineDataSet ) iSet ;
250
239
set .setDrawValues (!set .isDrawValuesEnabled ());
251
240
}
252
-
253
241
binding .chart1 .invalidate ();
254
242
}
255
243
case R .id .actionToggleIcons -> {
256
244
List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
257
245
258
246
for (ILineDataSet iSet : sets ) {
259
-
260
247
LineDataSet set = (LineDataSet ) iSet ;
261
248
set .setDrawIcons (!set .isDrawIconsEnabled ());
262
249
}
@@ -270,11 +257,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
270
257
}
271
258
}
272
259
case R .id .actionToggleFilled -> {
273
-
274
260
List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
275
261
276
262
for (ILineDataSet iSet : sets ) {
277
-
278
263
LineDataSet set = (LineDataSet ) iSet ;
279
264
set .setDrawFilled (!set .isDrawFilledEnabled ());
280
265
}
@@ -284,7 +269,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
284
269
List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
285
270
286
271
for (ILineDataSet iSet : sets ) {
287
-
288
272
LineDataSet set = (LineDataSet ) iSet ;
289
273
set .setDrawCircles (!set .isDrawCirclesEnabled ());
290
274
}
@@ -294,7 +278,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
294
278
List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
295
279
296
280
for (ILineDataSet iSet : sets ) {
297
-
298
281
LineDataSet set = (LineDataSet ) iSet ;
299
282
set .setMode (set .getMode () == LineDataSet .Mode .CUBIC_BEZIER ? LineDataSet .Mode .LINEAR : LineDataSet .Mode .CUBIC_BEZIER );
300
283
}
@@ -304,7 +287,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
304
287
List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
305
288
306
289
for (ILineDataSet iSet : sets ) {
307
-
308
290
LineDataSet set = (LineDataSet ) iSet ;
309
291
set .setMode (set .getMode () == LineDataSet .Mode .STEPPED ? LineDataSet .Mode .LINEAR : LineDataSet .Mode .STEPPED );
310
292
}
@@ -314,15 +296,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
314
296
List <ILineDataSet > sets = binding .chart1 .getData ().getDataSets ();
315
297
316
298
for (ILineDataSet iSet : sets ) {
317
-
318
299
LineDataSet set = (LineDataSet ) iSet ;
319
300
set .setMode (set .getMode () == LineDataSet .Mode .HORIZONTAL_BEZIER ? LineDataSet .Mode .LINEAR : LineDataSet .Mode .HORIZONTAL_BEZIER );
320
301
}
321
302
binding .chart1 .invalidate ();
322
303
}
323
304
case R .id .actionTogglePinch -> {
324
305
binding .chart1 .setPinchZoom (!binding .chart1 .isPinchZoomEnabled ());
325
-
326
306
binding .chart1 .invalidate ();
327
307
}
328
308
case R .id .actionToggleAutoScaleMinMax -> {
0 commit comments