|
| 1 | + |
| 2 | +package com.xxmassdeveloper.mpchartexample; |
| 3 | + |
| 4 | +import android.os.Bundle; |
| 5 | +import android.view.WindowManager; |
| 6 | + |
| 7 | +import com.github.mikephil.charting.charts.BarChart; |
| 8 | +import com.github.mikephil.charting.components.XAxis; |
| 9 | +import com.github.mikephil.charting.components.XAxis.XAxisPosition; |
| 10 | +import com.github.mikephil.charting.data.BarData; |
| 11 | +import com.github.mikephil.charting.data.BarDataSet; |
| 12 | +import com.github.mikephil.charting.data.BarEntry; |
| 13 | +import com.github.mikephil.charting.utils.ColorTemplate; |
| 14 | +import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase; |
| 15 | + |
| 16 | +import java.util.ArrayList; |
| 17 | + |
| 18 | +public class ScrollViewActivity extends DemoBase { |
| 19 | + |
| 20 | + private BarChart mChart; |
| 21 | + |
| 22 | + @Override |
| 23 | + protected void onCreate(Bundle savedInstanceState) { |
| 24 | + super.onCreate(savedInstanceState); |
| 25 | + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| 26 | + WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 27 | + setContentView(R.layout.activity_scrollview); |
| 28 | + |
| 29 | + mChart = (BarChart) findViewById(R.id.chart1); |
| 30 | + |
| 31 | + mChart.setDescription(""); |
| 32 | + |
| 33 | + // scaling can now only be done on x- and y-axis separately |
| 34 | + mChart.setPinchZoom(false); |
| 35 | + |
| 36 | + mChart.setDrawBarShadow(false); |
| 37 | + mChart.setDrawGridBackground(false); |
| 38 | + |
| 39 | + XAxis xAxis = mChart.getXAxis(); |
| 40 | + xAxis.setPosition(XAxisPosition.BOTTOM); |
| 41 | + xAxis.setLabelsToSkip(0); |
| 42 | + xAxis.setDrawGridLines(false); |
| 43 | + |
| 44 | + mChart.getAxisLeft().setDrawGridLines(false); |
| 45 | + |
| 46 | + mChart.getLegend().setEnabled(false); |
| 47 | + |
| 48 | + setData(10); |
| 49 | + } |
| 50 | + |
| 51 | + private void setData(int count) { |
| 52 | + |
| 53 | + ArrayList<BarEntry> yVals = new ArrayList<BarEntry>(); |
| 54 | + ArrayList<String> xVals = new ArrayList<String>(); |
| 55 | + |
| 56 | + for (int i = 0; i < count; i++) { |
| 57 | + float val = (float) (Math.random() * count) + 15; |
| 58 | + yVals.add(new BarEntry((int) val, i)); |
| 59 | + xVals.add((int) val + ""); |
| 60 | + } |
| 61 | + |
| 62 | + BarDataSet set = new BarDataSet(yVals, "Data Set"); |
| 63 | + set.setColors(ColorTemplate.VORDIPLOM_COLORS); |
| 64 | + set.setDrawValues(false); |
| 65 | + |
| 66 | + BarData data = new BarData(xVals, set); |
| 67 | + |
| 68 | + mChart.setData(data); |
| 69 | + mChart.invalidate(); |
| 70 | + mChart.animateY(800); |
| 71 | + } |
| 72 | +} |
0 commit comments