Search in sources :

Example 21 with MPPointF

use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.

the class BarChartActivity method onValueSelected.

@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
    if (e == null)
        return;
    RectF bounds = mOnValueSelectedRectF;
    mChart.getBarBounds((BarEntry) e, bounds);
    MPPointF position = mChart.getPosition(e, AxisDependency.LEFT);
    Log.i("bounds", bounds.toString());
    Log.i("position", position.toString());
    Log.i("x-index", "low: " + mChart.getLowestVisibleX() + ", high: " + mChart.getHighestVisibleX());
    MPPointF.recycleInstance(position);
}
Also used : RectF(android.graphics.RectF) MPPointF(com.github.mikephil.charting.utils.MPPointF) SuppressLint(android.annotation.SuppressLint)

Example 22 with MPPointF

use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.

the class BubbleChartActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    int count = mSeekBarX.getProgress();
    int range = mSeekBarY.getProgress();
    tvX.setText("" + count);
    tvY.setText("" + range);
    ArrayList<BubbleEntry> yVals1 = new ArrayList<BubbleEntry>();
    ArrayList<BubbleEntry> yVals2 = new ArrayList<BubbleEntry>();
    ArrayList<BubbleEntry> yVals3 = new ArrayList<BubbleEntry>();
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        float size = (float) (Math.random() * range);
        yVals1.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
    }
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        float size = (float) (Math.random() * range);
        yVals2.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
    }
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        float size = (float) (Math.random() * range);
        yVals3.add(new BubbleEntry(i, val, size));
    }
    // create a dataset and give it a type
    BubbleDataSet set1 = new BubbleDataSet(yVals1, "DS 1");
    set1.setDrawIcons(false);
    set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
    set1.setDrawValues(true);
    BubbleDataSet set2 = new BubbleDataSet(yVals2, "DS 2");
    set2.setDrawIcons(false);
    set2.setIconsOffset(new MPPointF(0, 15));
    set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
    set2.setDrawValues(true);
    BubbleDataSet set3 = new BubbleDataSet(yVals3, "DS 3");
    set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
    set3.setDrawValues(true);
    ArrayList<IBubbleDataSet> dataSets = new ArrayList<IBubbleDataSet>();
    // add the datasets
    dataSets.add(set1);
    dataSets.add(set2);
    dataSets.add(set3);
    // create a data object with the datasets
    BubbleData data = new BubbleData(dataSets);
    data.setDrawValues(false);
    data.setValueTypeface(mTfLight);
    data.setValueTextSize(8f);
    data.setValueTextColor(Color.WHITE);
    data.setHighlightCircleWidth(1.5f);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleData(com.github.mikephil.charting.data.BubbleData) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) MPPointF(com.github.mikephil.charting.utils.MPPointF) ArrayList(java.util.ArrayList) IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleDataSet(com.github.mikephil.charting.data.BubbleDataSet)

Example 23 with MPPointF

use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.

the class HorizontalBarChartActivity method onValueSelected.

@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {
    if (e == null)
        return;
    RectF bounds = mOnValueSelectedRectF;
    mChart.getBarBounds((BarEntry) e, bounds);
    MPPointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex()).getAxisDependency());
    Log.i("bounds", bounds.toString());
    Log.i("position", position.toString());
    MPPointF.recycleInstance(position);
}
Also used : RectF(android.graphics.RectF) MPPointF(com.github.mikephil.charting.utils.MPPointF) SuppressLint(android.annotation.SuppressLint)

Example 24 with MPPointF

use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.

the class PieChartActivity method setData.

private void setData(int count, float range) {
    float mult = range;
    ArrayList<PieEntry> entries = new ArrayList<PieEntry>();
    // the chart.
    for (int i = 0; i < count; i++) {
        entries.add(new PieEntry((float) ((Math.random() * mult) + mult / 5), mParties[i % mParties.length], getResources().getDrawable(R.drawable.star)));
    }
    PieDataSet dataSet = new PieDataSet(entries, "Election Results");
    dataSet.setDrawIcons(false);
    dataSet.setSliceSpace(3f);
    dataSet.setIconsOffset(new MPPointF(0, 40));
    dataSet.setSelectionShift(5f);
    // add a lot of colors
    ArrayList<Integer> colors = new ArrayList<Integer>();
    for (int c : ColorTemplate.VORDIPLOM_COLORS) colors.add(c);
    for (int c : ColorTemplate.JOYFUL_COLORS) colors.add(c);
    for (int c : ColorTemplate.COLORFUL_COLORS) colors.add(c);
    for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c);
    for (int c : ColorTemplate.PASTEL_COLORS) colors.add(c);
    colors.add(ColorTemplate.getHoloBlue());
    dataSet.setColors(colors);
    //dataSet.setSelectionShift(0f);
    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.WHITE);
    data.setValueTypeface(mTfLight);
    mChart.setData(data);
    // undo all highlights
    mChart.highlightValues(null);
    mChart.invalidate();
}
Also used : PercentFormatter(com.github.mikephil.charting.formatter.PercentFormatter) PieEntry(com.github.mikephil.charting.data.PieEntry) PieDataSet(com.github.mikephil.charting.data.PieDataSet) MPPointF(com.github.mikephil.charting.utils.MPPointF) ArrayList(java.util.ArrayList) PieData(com.github.mikephil.charting.data.PieData)

Example 25 with MPPointF

use of com.github.mikephil.charting.utils.MPPointF in project MPAndroidChart by PhilJay.

the class BarLineChartBase method zoomIn.

/**
     * Zooms in by 1.4f, into the charts center.
     */
public void zoomIn() {
    MPPointF center = mViewPortHandler.getContentCenter();
    mViewPortHandler.zoomIn(center.x, -center.y, mZoomMatrixBuffer);
    mViewPortHandler.refresh(mZoomMatrixBuffer, this, false);
    MPPointF.recycleInstance(center);
    // Range might have changed, which means that Y-axis labels
    // could have changed in size, affecting Y-axis size.
    // So we need to recalculate offsets.
    calculateOffsets();
    postInvalidate();
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF)

Aggregations

MPPointF (com.github.mikephil.charting.utils.MPPointF)43 Paint (android.graphics.Paint)13 Drawable (android.graphics.drawable.Drawable)9 RectF (android.graphics.RectF)5 TextPaint (android.text.TextPaint)5 Entry (com.github.mikephil.charting.data.Entry)5 PieEntry (com.github.mikephil.charting.data.PieEntry)4 Transformer (com.github.mikephil.charting.utils.Transformer)4 Path (android.graphics.Path)3 RadarEntry (com.github.mikephil.charting.data.RadarEntry)3 IPieDataSet (com.github.mikephil.charting.interfaces.datasets.IPieDataSet)3 SuppressLint (android.annotation.SuppressLint)2 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)2 Chart (com.github.mikephil.charting.charts.Chart)2 BarEntry (com.github.mikephil.charting.data.BarEntry)2 BubbleData (com.github.mikephil.charting.data.BubbleData)2 BubbleEntry (com.github.mikephil.charting.data.BubbleEntry)2 PieData (com.github.mikephil.charting.data.PieData)2 PieDataSet (com.github.mikephil.charting.data.PieDataSet)2 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)2