Search in sources :

Example 16 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class BubbleChartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_bubblechart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarX.setOnSeekBarChangeListener(this);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mChart = (BubbleChart) findViewById(R.id.chart1);
    mChart.getDescription().setEnabled(false);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.setTouchEnabled(true);
    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);
    mChart.setMaxVisibleValueCount(200);
    mChart.setPinchZoom(true);
    mSeekBarX.setProgress(10);
    mSeekBarY.setProgress(50);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setTypeface(mTfLight);
    YAxis yl = mChart.getAxisLeft();
    yl.setTypeface(mTfLight);
    yl.setSpaceTop(30f);
    yl.setSpaceBottom(30f);
    yl.setDrawZeroLine(false);
    mChart.getAxisRight().setEnabled(false);
    XAxis xl = mChart.getXAxis();
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setTypeface(mTfLight);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 17 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class HorizontalBarChartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_horizontalbarchart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mChart = (HorizontalBarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    // mChart.setHighlightEnabled(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    mChart.getDescription().setEnabled(false);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    mChart.setMaxVisibleValueCount(60);
    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    // draw shadows for each bar that show the maximum value
    // mChart.setDrawBarShadow(true);
    mChart.setDrawGridBackground(false);
    XAxis xl = mChart.getXAxis();
    xl.setPosition(XAxisPosition.BOTTOM);
    xl.setTypeface(mTfLight);
    xl.setDrawAxisLine(true);
    xl.setDrawGridLines(false);
    xl.setGranularity(10f);
    YAxis yl = mChart.getAxisLeft();
    yl.setTypeface(mTfLight);
    yl.setDrawAxisLine(true);
    yl.setDrawGridLines(true);
    // this replaces setStartAtZero(true)
    yl.setAxisMinimum(0f);
    //        yl.setInverted(true);
    YAxis yr = mChart.getAxisRight();
    yr.setTypeface(mTfLight);
    yr.setDrawAxisLine(true);
    yr.setDrawGridLines(false);
    // this replaces setStartAtZero(true)
    yr.setAxisMinimum(0f);
    //        yr.setInverted(true);
    setData(12, 50);
    mChart.setFitBars(true);
    mChart.animateY(2500);
    // setting data
    mSeekBarY.setProgress(50);
    mSeekBarX.setProgress(12);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mSeekBarX.setOnSeekBarChangeListener(this);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setXEntrySpace(4f);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 18 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class MultiLineChartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_linechart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarX.setOnSeekBarChangeListener(this);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.getDescription().setEnabled(false);
    mChart.setDrawBorders(false);
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setDrawAxisLine(false);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getXAxis().setDrawAxisLine(false);
    mChart.getXAxis().setDrawGridLines(false);
    // enable touch gestures
    mChart.setTouchEnabled(true);
    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);
    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(false);
    mSeekBarX.setProgress(20);
    mSeekBarY.setProgress(100);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend)

Example 19 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class PerformanceLineChart method setData.

private void setData(int count, float range) {
    ArrayList<Entry> yVals = new ArrayList<Entry>();
    for (int i = 0; i < count; i++) {
        float mult = (range + 1);
        // + (float)
        float val = (float) (Math.random() * mult) + 3;
        // ((mult *
        // 0.1) / 10);
        yVals.add(new Entry(i * 0.001f, val));
    }
    // create a dataset and give it a type
    LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
    set1.setColor(Color.BLACK);
    set1.setLineWidth(0.5f);
    set1.setDrawValues(false);
    set1.setDrawCircles(false);
    set1.setMode(LineDataSet.Mode.LINEAR);
    set1.setDrawFilled(false);
    // create a data object with the datasets
    LineData data = new LineData(set1);
    // set data
    mChart.setData(data);
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    l.setEnabled(false);
}
Also used : Entry(com.github.mikephil.charting.data.Entry) LineData(com.github.mikephil.charting.data.LineData) Legend(com.github.mikephil.charting.components.Legend) LineDataSet(com.github.mikephil.charting.data.LineDataSet) ArrayList(java.util.ArrayList)

Example 20 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class PiePolylineChartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_piechart);
    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setProgress(10);
    mSeekBarX.setOnSeekBarChangeListener(this);
    mSeekBarY.setOnSeekBarChangeListener(this);
    mChart = (PieChart) findViewById(R.id.chart1);
    mChart.setUsePercentValues(true);
    mChart.getDescription().setEnabled(false);
    mChart.setExtraOffsets(5, 10, 5, 5);
    mChart.setDragDecelerationFrictionCoef(0.95f);
    tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    mChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
    mChart.setCenterText(generateCenterSpannableText());
    mChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
    mChart.setDrawHoleEnabled(true);
    mChart.setHoleColor(Color.WHITE);
    mChart.setTransparentCircleColor(Color.WHITE);
    mChart.setTransparentCircleAlpha(110);
    mChart.setHoleRadius(58f);
    mChart.setTransparentCircleRadius(61f);
    mChart.setDrawCenterText(true);
    mChart.setRotationAngle(0);
    // enable rotation of the chart by touch
    mChart.setRotationEnabled(true);
    mChart.setHighlightPerTapEnabled(true);
    // mChart.setUnit(" €");
    // mChart.setDrawUnitsInChart(true);
    // add a selection listener
    mChart.setOnChartValueSelectedListener(this);
    setData(4, 100);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
    // mChart.spin(2000, 0, 360);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setEnabled(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend)

Aggregations

Legend (com.github.mikephil.charting.components.Legend)31 XAxis (com.github.mikephil.charting.components.XAxis)21 YAxis (com.github.mikephil.charting.components.YAxis)19 Typeface (android.graphics.Typeface)7 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)6 View (android.view.View)5 AxisBase (com.github.mikephil.charting.components.AxisBase)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 ArrayList (java.util.ArrayList)3 Paint (android.graphics.Paint)2 LineData (com.github.mikephil.charting.data.LineData)2 LineDataSet (com.github.mikephil.charting.data.LineDataSet)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 ValueAnimator (android.animation.ValueAnimator)1 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)1 DashPathEffect (android.graphics.DashPathEffect)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 ChartAnimator (com.github.mikephil.charting.animation.ChartAnimator)1 BarChart (com.github.mikephil.charting.charts.BarChart)1