Search in sources :

Example 1 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class Chart method drawMarkers.

/**
     * draws all MarkerViews on the highlighted positions
     */
protected void drawMarkers(Canvas canvas) {
    // if there is no marker view or drawing marker is disabled
    if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight())
        return;
    for (int i = 0; i < mIndicesToHighlight.length; i++) {
        Highlight highlight = mIndicesToHighlight[i];
        IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex());
        Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
        int entryIndex = set.getEntryIndex(e);
        // make sure entry not null
        if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX())
            continue;
        float[] pos = getMarkerPosition(highlight);
        // check bounds
        if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
            continue;
        // callbacks to update the content
        mMarker.refreshContent(e, highlight);
        // draw the marker
        mMarker.draw(canvas, pos[0], pos[1]);
    }
}
Also used : Entry(com.github.mikephil.charting.data.Entry) Highlight(com.github.mikephil.charting.highlight.Highlight) IDataSet(com.github.mikephil.charting.interfaces.datasets.IDataSet) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 2 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class RadarChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    float sliceangle = mChart.getSliceAngle();
    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = mChart.getFactor();
    MPPointF center = mChart.getCenterOffsets();
    MPPointF pOut = MPPointF.getInstance(0, 0);
    RadarData radarData = mChart.getData();
    for (Highlight high : indices) {
        IRadarDataSet set = radarData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        RadarEntry e = set.getEntryForIndex((int) high.getX());
        if (!isInBoundsX(e, set))
            continue;
        float y = (e.getY() - mChart.getYChartMin());
        Utils.getPosition(center, y * factor * mAnimator.getPhaseY(), sliceangle * high.getX() * mAnimator.getPhaseX() + mChart.getRotationAngle(), pOut);
        high.setDraw(pOut.x, pOut.y);
        // draw the lines
        drawHighlightLines(c, pOut.x, pOut.y, set);
        if (set.isDrawHighlightCircleEnabled()) {
            if (!Float.isNaN(pOut.x) && !Float.isNaN(pOut.y)) {
                int strokeColor = set.getHighlightCircleStrokeColor();
                if (strokeColor == ColorTemplate.COLOR_NONE) {
                    strokeColor = set.getColor(0);
                }
                if (set.getHighlightCircleStrokeAlpha() < 255) {
                    strokeColor = ColorTemplate.colorWithAlpha(strokeColor, set.getHighlightCircleStrokeAlpha());
                }
                drawHighlightCircle(c, pOut, set.getHighlightCircleInnerRadius(), set.getHighlightCircleOuterRadius(), set.getHighlightCircleFillColor(), strokeColor, set.getHighlightCircleStrokeWidth());
            }
        }
    }
    MPPointF.recycleInstance(center);
    MPPointF.recycleInstance(pOut);
}
Also used : RadarEntry(com.github.mikephil.charting.data.RadarEntry) Highlight(com.github.mikephil.charting.highlight.Highlight) IRadarDataSet(com.github.mikephil.charting.interfaces.datasets.IRadarDataSet) MPPointF(com.github.mikephil.charting.utils.MPPointF) RadarData(com.github.mikephil.charting.data.RadarData) Paint(android.graphics.Paint)

Example 3 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class BubbleChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    BubbleData bubbleData = mChart.getBubbleData();
    float phaseY = mAnimator.getPhaseY();
    for (Highlight high : indices) {
        IBubbleDataSet set = bubbleData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        final BubbleEntry entry = set.getEntryForXValue(high.getX(), high.getY());
        if (entry.getY() != high.getY())
            continue;
        if (!isInBoundsX(entry, set))
            continue;
        Transformer trans = mChart.getTransformer(set.getAxisDependency());
        sizeBuffer[0] = 0f;
        sizeBuffer[2] = 1f;
        trans.pointValuesToPixel(sizeBuffer);
        boolean normalizeSize = set.isNormalizeSizeEnabled();
        // calcualte the full width of 1 step on the x-axis
        final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]);
        final float maxBubbleHeight = Math.abs(mViewPortHandler.contentBottom() - mViewPortHandler.contentTop());
        final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth);
        pointBuffer[0] = entry.getX();
        pointBuffer[1] = (entry.getY()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);
        high.setDraw(pointBuffer[0], pointBuffer[1]);
        float shapeHalf = getShapeSize(entry.getSize(), set.getMaxSize(), referenceSize, normalizeSize) / 2f;
        if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf) || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf))
            continue;
        if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf))
            continue;
        if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf))
            break;
        final int originalColor = set.getColor((int) entry.getX());
        Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor), Color.blue(originalColor), _hsvBuffer);
        _hsvBuffer[2] *= 0.5f;
        final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer);
        mHighlightPaint.setColor(color);
        mHighlightPaint.setStrokeWidth(set.getHighlightCircleWidth());
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
    }
}
Also used : BubbleData(com.github.mikephil.charting.data.BubbleData) IBubbleDataSet(com.github.mikephil.charting.interfaces.datasets.IBubbleDataSet) BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) Highlight(com.github.mikephil.charting.highlight.Highlight) Transformer(com.github.mikephil.charting.utils.Transformer)

Example 4 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project MPAndroidChart by PhilJay.

the class BarLineChartTouchListener method performHighlightDrag.

/**
     * Highlights upon dragging, generates callbacks for the selection-listener.
     *
     * @param e
     */
private void performHighlightDrag(MotionEvent e) {
    Highlight h = mChart.getHighlightByTouchPoint(e.getX(), e.getY());
    if (h != null && !h.equalTo(mLastHighlighted)) {
        mLastHighlighted = h;
        mChart.highlightValue(h, true);
    }
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight)

Example 5 with Highlight

use of com.github.mikephil.charting.highlight.Highlight in project AdMoney by ErnestoGonAr.

the class Reporte_Ingresos method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        initData();
    } catch (NullPointerException e) {
        Toast toast = Toast.makeText(this, "No hay Ingresos", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.show();
        return;
    }
    setContentView(R.layout.activity_reporte__ingresos);
    pieChart = (PieChart) findViewById(R.id.grafico_ingresos);
    pieChart.setRotationEnabled(true);
    pieChart.setHoleRadius(30f);
    pieChart.setCenterTextSize(10);
    pieChart.setTransparentCircleAlpha(0);
    Description d = pieChart.getDescription();
    d.setText("");
    pieChart.setDescription(d);
    pieChart.getLegend().setOrientation(Legend.LegendOrientation.VERTICAL);
    pieChart.setEntryLabelTextSize(4);
    pieChart.getLegend().setTextSize(12);
    pieChart.getLegend().setPosition(Legend.LegendPosition.LEFT_OF_CHART);
    if (xData.length == 0)
        return;
    addData();
    pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {

        @Override
        public void onValueSelected(Entry e, Highlight h) {
            Log.d(TAG, "onValueSelected: Value selected from chart");
            Log.d(TAG, e.toString());
            Log.d(TAG, h.toString());
            int pos1 = e.toString().indexOf("Entry, x: 0.0 y: ");
            String res = e.toString().substring(pos1 + 17);
            for (int i = 0; i < yData.length; i++) {
                if (yData[i] == Float.parseFloat(res)) {
                    pos1 = i;
                    break;
                }
            }
            String categoria = xData[pos1];
            Toast.makeText(Reporte_Ingresos.this, "Ha obtenido $" + res + " en ingresos\n" + "por " + categoria, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onNothingSelected() {
        }
    });
    spinner = (Spinner) findViewById(R.id.spinner_r_ingresos);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            calendar.setText("Selecciona una fecha");
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    año = 2017;
    mes = 5;
    diad = 17;
    calendar = (EditText) findViewById(R.id.fecha_r_ingresos);
    calendar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //To show current date in the datepicker
            final Calendar mcurrentDate = Calendar.getInstance();
            mYear = mcurrentDate.get(Calendar.YEAR);
            mMonth = mcurrentDate.get(Calendar.MONTH);
            mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
            DatePickerDialog mDatePicker = new DatePickerDialog(Reporte_Ingresos.this, new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                    // TODO Auto-generated method stub
                    año = selectedyear;
                    mes = selectedmonth + 1;
                    diad = selectedday;
                    calendar.setText(selectedyear + "-" + (selectedmonth + 1) + "-" + selectedday);
                }
            }, mYear, mMonth, mDay);
            mDatePicker.setTitle("Selecciona fecha");
            mDatePicker.show();
        }
    });
    consultar = (Button) findViewById(R.id.consultar);
    consultar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (calendar.getText().toString().equals("Selecciona una fecha")) {
                calendar.requestFocus();
                calendar.callOnClick();
                return;
            }
            String[][] data;
            switch(spinner.getSelectedItemPosition()) {
                case 1:
                    data = bd.obtenerIngresos(diad + "", mes + "", año + "");
                    if (data == null) {
                        Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
                        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                        toast.show();
                        pieChart.setVisibility(View.INVISIBLE);
                        break;
                    }
                    pieChart.clear();
                    initData(data);
                    addData();
                    pieChart.setVisibility(View.VISIBLE);
                    break;
                case 2:
                    data = bd.obtenerIngresos(mes + "", año + "");
                    if (data == null) {
                        Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
                        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                        toast.show();
                        pieChart.setVisibility(View.INVISIBLE);
                        break;
                    }
                    pieChart.clear();
                    initData(data);
                    addData();
                    pieChart.setVisibility(View.VISIBLE);
                    break;
                case 3:
                    data = bd.obtenerIngresos(año + "");
                    if (data == null) {
                        Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
                        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                        toast.show();
                        pieChart.setVisibility(View.INVISIBLE);
                        break;
                    }
                    pieChart.clear();
                    initData(data);
                    addData();
                    pieChart.setVisibility(View.VISIBLE);
                    break;
                default:
                    pieChart.clear();
                    initData();
                    addData();
                    pieChart.setVisibility(View.VISIBLE);
                    break;
            }
        }
    });
}
Also used : OnChartValueSelectedListener(com.github.mikephil.charting.listener.OnChartValueSelectedListener) Description(com.github.mikephil.charting.components.Description) Highlight(com.github.mikephil.charting.highlight.Highlight) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) View(android.view.View) AdapterView(android.widget.AdapterView) Entry(com.github.mikephil.charting.data.Entry) PieEntry(com.github.mikephil.charting.data.PieEntry) Toast(android.widget.Toast) AdapterView(android.widget.AdapterView) DatePicker(android.widget.DatePicker)

Aggregations

Highlight (com.github.mikephil.charting.highlight.Highlight)13 Entry (com.github.mikephil.charting.data.Entry)5 MPPointD (com.github.mikephil.charting.utils.MPPointD)3 DatePickerDialog (android.app.DatePickerDialog)2 Paint (android.graphics.Paint)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 DatePicker (android.widget.DatePicker)2 Toast (android.widget.Toast)2 Description (com.github.mikephil.charting.components.Description)2 PieEntry (com.github.mikephil.charting.data.PieEntry)2 OnChartValueSelectedListener (com.github.mikephil.charting.listener.OnChartValueSelectedListener)2 Transformer (com.github.mikephil.charting.utils.Transformer)2 Calendar (java.util.Calendar)2 SuppressLint (android.annotation.SuppressLint)1 Chart (com.github.mikephil.charting.charts.Chart)1 CombinedChart (com.github.mikephil.charting.charts.CombinedChart)1 BarData (com.github.mikephil.charting.data.BarData)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 BubbleData (com.github.mikephil.charting.data.BubbleData)1