use of com.github.mikephil.charting.data.Entry in project Gadgetbridge by Freeyourgadget.
the class LiveActivityFragment method addEntries.
private void addEntries(int timestamp) {
mTotalStepsChart.setSingleEntryYValue(mSteps.getTotalSteps());
YAxis stepsPerMinuteCurrentYAxis = mStepsPerMinuteCurrentChart.getAxisLeft();
int maxStepsPerMinute = mSteps.getMaxStepsPerMinute();
// int extraRoom = maxStepsPerMinute/5;
// buggy in MPAndroidChart? Disable.
// stepsPerMinuteCurrentYAxis.setAxisMaxValue(Math.max(MIN_STEPS_PER_MINUTE, maxStepsPerMinute + extraRoom));
LimitLine target = new LimitLine(maxStepsPerMinute);
stepsPerMinuteCurrentYAxis.removeAllLimitLines();
stepsPerMinuteCurrentYAxis.addLimitLine(target);
int stepsPerMinute = mSteps.getStepsPerMinute(true);
mStepsPerMinuteCurrentChart.setSingleEntryYValue(stepsPerMinute);
if (!addHistoryDataSet(false)) {
return;
}
ChartData data = mStepsPerMinuteHistoryChart.getData();
if (stepsPerMinute < 0) {
stepsPerMinute = 0;
}
mHistorySet.addEntry(new Entry(timestamp, stepsPerMinute));
int hr = getCurrentHeartRate();
if (hr < 0) {
hr = 0;
}
mHeartRateSet.addEntry(new Entry(timestamp, hr));
}
use of com.github.mikephil.charting.data.Entry 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;
}
}
});
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class SummaryFragment method generatePieData.
protected PieData generatePieData() {
ArrayList<Entry> entries = new ArrayList<Entry>();
ArrayList<String> xVals = new ArrayList<String>();
xVals.add(getString(R.string.chart_wellbehaved));
xVals.add(getString(R.string.chart_hogs));
xVals.add(getString(R.string.chart_bugs));
int wellbehaved = mMainActivity.mWellbehaved;
int hogs = mMainActivity.mHogs;
int bugs = mMainActivity.mBugs;
entries.add(new Entry((float) (wellbehaved), 1));
entries.add(new Entry((float) (hogs), 2));
entries.add(new Entry((float) (bugs), 3));
PieDataSet ds1 = new PieDataSet(entries, getString(R.string.summary_chart_center_text));
ds1.setColors(Constants.CARAT_COLORS);
ds1.setSliceSpace(2f);
PieData d = new PieData(xVals, ds1);
return d;
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class BarLineChartBase method drawLimitLines.
/**
* Draws the limit lines if there are one.
*/
private void drawLimitLines() {
ArrayList<LimitLine> limitLines = mData.getLimitLines();
if (limitLines == null)
return;
float[] pts = new float[4];
for (int i = 0; i < limitLines.size(); i++) {
LimitLine l = limitLines.get(i);
pts[1] = l.getLimit();
pts[3] = l.getLimit();
mTrans.pointValuesToPixel(pts);
pts[0] = 0;
pts[2] = getWidth();
mLimitLinePaint.setColor(l.getLineColor());
mLimitLinePaint.setPathEffect(l.getDashPathEffect());
mLimitLinePaint.setStrokeWidth(l.getLineWidth());
mDrawCanvas.drawLines(pts, mLimitLinePaint);
// if drawing the limit-value is enabled
if (l.isDrawValueEnabled()) {
PointF pos = getPosition(new Entry(l.getLimit(), 0));
// save text align
Align align = mValuePaint.getTextAlign();
float xOffset = Utils.convertDpToPixel(4f);
float yOffset = l.getLineWidth() + xOffset;
String label = mValueFormatter.getFormattedValue(l.getLimit());
if (mDrawUnitInChart)
label += mUnit;
if (l.getLabelPosition() == LimitLabelPosition.RIGHT) {
mValuePaint.setTextAlign(Align.RIGHT);
mDrawCanvas.drawText(label, getWidth() - mOffsetRight - xOffset, pos.y - yOffset, mValuePaint);
} else {
mValuePaint.setTextAlign(Align.LEFT);
mDrawCanvas.drawText(label, mOffsetLeft + xOffset, pos.y - yOffset, mValuePaint);
}
mValuePaint.setTextAlign(align);
}
}
}
use of com.github.mikephil.charting.data.Entry in project carat by amplab.
the class BarChart method drawHighlights.
@Override
protected void drawHighlights() {
int setCount = mData.getDataSetCount();
for (int i = 0; i < mIndicesToHightlight.length; i++) {
Highlight h = mIndicesToHightlight[i];
int index = h.getXIndex();
int dataSetIndex = h.getDataSetIndex();
BarDataSet set = (BarDataSet) mData.getDataSetByIndex(dataSetIndex);
if (set == null)
continue;
mHighlightPaint.setColor(set.getHighLightColor());
mHighlightPaint.setAlpha(set.getHighLightAlpha());
// check outofbounds
if (index < mData.getYValCount() && index >= 0 && index < (mDeltaX * mPhaseX) / mData.getDataSetCount()) {
Entry e = getEntryByDataSetIndex(index, dataSetIndex);
if (e == null)
continue;
// calculate the correct x-position
float x = index * setCount + dataSetIndex + mData.getGroupSpace() / 2f + mData.getGroupSpace() * index;
float y = e.getVal();
prepareBar(x, y, set.getBarSpace());
mDrawCanvas.drawRect(mBarRect, mHighlightPaint);
if (mDrawHighlightArrow) {
mHighlightPaint.setAlpha(255);
// distance between highlight arrow and bar
float offsetY = mDeltaY * 0.07f;
Path arrow = new Path();
arrow.moveTo(x + 0.5f, y + offsetY * 0.3f);
arrow.lineTo(x + 0.2f, y + offsetY);
arrow.lineTo(x + 0.8f, y + offsetY);
mTrans.pathValueToPixel(arrow);
mDrawCanvas.drawPath(arrow, mHighlightPaint);
}
}
}
}
Aggregations