Search in sources :

Example 11 with Highlight

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

the class PieRadarChartTouchListener method onSingleTapUp.

@Override
public boolean onSingleTapUp(MotionEvent e) {
    mLastGesture = ChartGesture.SINGLE_TAP;
    OnChartGestureListener l = mChart.getOnChartGestureListener();
    if (l != null) {
        l.onChartSingleTapped(e);
    }
    if (!mChart.isHighlightPerTapEnabled()) {
        return false;
    }
    Highlight high = mChart.getHighlightByTouchPoint(e.getX(), e.getY());
    performHighlight(high, e);
    return true;
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight)

Example 12 with Highlight

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

the class LineChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    LineData lineData = mChart.getLineData();
    for (Highlight high : indices) {
        ILineDataSet set = lineData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        Entry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator.getPhaseY());
        high.setDraw((float) pix.x, (float) pix.y);
        // draw the lines
        drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
    }
}
Also used : LineData(com.github.mikephil.charting.data.LineData) Entry(com.github.mikephil.charting.data.Entry) Highlight(com.github.mikephil.charting.highlight.Highlight) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) MPPointD(com.github.mikephil.charting.utils.MPPointD)

Example 13 with Highlight

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

the class Reporte_Egresos method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        initData();
    } catch (NullPointerException e) {
        Toast toast = Toast.makeText(this, "No hay Egresos", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.show();
        return;
    }
    setContentView(R.layout.activity_reporte__egresos);
    pieChart = (PieChart) findViewById(R.id.grafico_egresos);
    pieChart.setRotationEnabled(true);
    pieChart.setHoleRadius(30f);
    pieChart.setCenterTextSize(10);
    pieChart.setEntryLabelTextSize(4);
    pieChart.setTransparentCircleAlpha(0);
    Description d = pieChart.getDescription();
    d.setText("");
    pieChart.setDescription(d);
    pieChart.getLegend().setOrientation(Legend.LegendOrientation.VERTICAL);
    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_Egresos.this, "Ha gastado $" + res + " en " + categoria, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onNothingSelected() {
        }
    });
    spinner = (Spinner) findViewById(R.id.spinner_r_egresos);
    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_egresos);
    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_Egresos.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_e);
    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:
                    String dia = calendar.getText().toString();
                    data = bd.obtenerEgresos(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.obtenerEgresos(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.obtenerEgresos(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