|
2 | 2 | package com.xxmassdeveloper.mpchartexample; |
3 | 3 |
|
4 | 4 | import android.graphics.Color; |
5 | | -import android.graphics.Paint; |
6 | 5 | import android.os.Bundle; |
7 | 6 | import android.util.Log; |
8 | 7 | import android.view.Menu; |
|
16 | 15 | import com.github.mikephil.charting.charts.LineChart; |
17 | 16 | import com.github.mikephil.charting.components.Legend; |
18 | 17 | import com.github.mikephil.charting.components.Legend.LegendForm; |
19 | | -import com.github.mikephil.charting.components.Legend.LegendPosition; |
20 | 18 | import com.github.mikephil.charting.components.XAxis; |
21 | 19 | import com.github.mikephil.charting.components.YAxis; |
22 | 20 | import com.github.mikephil.charting.components.YAxis.AxisDependency; |
@@ -243,6 +241,7 @@ public boolean onOptionsItemSelected(MenuItem item) { |
243 | 241 | } |
244 | 242 | case R.id.animateX: { |
245 | 243 | mChart.animateX(3000); |
| 244 | + //mChart.highlightValue(9.7f, 1, false); |
246 | 245 | break; |
247 | 246 | } |
248 | 247 | case R.id.animateY: { |
@@ -287,30 +286,39 @@ private void setData(int count, float range) { |
287 | 286 |
|
288 | 287 | for (int i = 0; i < count; i++) { |
289 | 288 | float mult = range / 2f; |
290 | | - float val = (float) (Math.random() * mult) + 50;// + (float) |
291 | | - // ((mult * |
292 | | - // 0.1) / 10); |
| 289 | + float val = (float) (Math.random() * mult) + 50; |
293 | 290 | yVals1.add(new Entry(i, val)); |
294 | 291 | } |
295 | 292 |
|
296 | 293 | ArrayList<Entry> yVals2 = new ArrayList<Entry>(); |
297 | 294 |
|
298 | | - for (int i = 0; i < count; i++) { |
| 295 | + for (int i = 0; i < count-1; i++) { |
299 | 296 | float mult = range; |
300 | | - float val = (float) (Math.random() * mult) + 450;// + (float) |
301 | | - // ((mult * |
302 | | - // 0.1) / 10); |
| 297 | + float val = (float) (Math.random() * mult) + 450; |
303 | 298 | yVals2.add(new Entry(i, val)); |
| 299 | +// if(i == 10) { |
| 300 | +// yVals2.add(new Entry(i, val + 50)); |
| 301 | +// } |
| 302 | + } |
| 303 | + |
| 304 | + ArrayList<Entry> yVals3 = new ArrayList<Entry>(); |
| 305 | + |
| 306 | + for (int i = 0; i < count; i++) { |
| 307 | + float mult = range; |
| 308 | + float val = (float) (Math.random() * mult) + 500; |
| 309 | + yVals3.add(new Entry(i, val)); |
304 | 310 | } |
305 | 311 |
|
306 | | - LineDataSet set1, set2; |
| 312 | + LineDataSet set1, set2, set3; |
307 | 313 |
|
308 | 314 | if (mChart.getData() != null && |
309 | 315 | mChart.getData().getDataSetCount() > 0) { |
310 | 316 | set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0); |
311 | 317 | set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1); |
| 318 | + set3 = (LineDataSet) mChart.getData().getDataSetByIndex(2); |
312 | 319 | set1.setValues(yVals1); |
313 | 320 | set2.setValues(yVals2); |
| 321 | + set3.setValues(yVals3); |
314 | 322 | mChart.getData().notifyDataChanged(); |
315 | 323 | mChart.notifyDataSetChanged(); |
316 | 324 | } else { |
@@ -344,12 +352,19 @@ private void setData(int count, float range) { |
344 | 352 | set2.setHighLightColor(Color.rgb(244, 117, 117)); |
345 | 353 | //set2.setFillFormatter(new MyFillFormatter(900f)); |
346 | 354 |
|
347 | | - ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); |
348 | | - dataSets.add(set1); // add the datasets |
349 | | - dataSets.add(set2); |
| 355 | + set3 = new LineDataSet(yVals3, "DataSet 3"); |
| 356 | + set3.setAxisDependency(AxisDependency.RIGHT); |
| 357 | + set3.setColor(Color.YELLOW); |
| 358 | + set3.setCircleColor(Color.WHITE); |
| 359 | + set3.setLineWidth(2f); |
| 360 | + set3.setCircleRadius(3f); |
| 361 | + set3.setFillAlpha(65); |
| 362 | + set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200)); |
| 363 | + set3.setDrawCircleHole(false); |
| 364 | + set3.setHighLightColor(Color.rgb(244, 117, 117)); |
350 | 365 |
|
351 | 366 | // create a data object with the datasets |
352 | | - LineData data = new LineData(dataSets); |
| 367 | + LineData data = new LineData(set1, set2, set3); |
353 | 368 | data.setValueTextColor(Color.WHITE); |
354 | 369 | data.setValueTextSize(9f); |
355 | 370 |
|
|
0 commit comments