use of com.github.mikephil.charting.components.YAxis in project CryptoBuddy by Patchett.
the class GraphFragment method setUpChart.
public void setUpChart() {
XAxis xAxis = lineChart.getXAxis();
xAxis.setDrawAxisLine(true);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
xAxis.setAvoidFirstLastClipping(true);
lineChart.getAxisLeft().setEnabled(true);
lineChart.getAxisLeft().setDrawGridLines(false);
lineChart.getXAxis().setDrawGridLines(false);
lineChart.getAxisRight().setEnabled(false);
lineChart.getLegend().setEnabled(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setScaleEnabled(false);
lineChart.getDescription().setEnabled(false);
lineChart.setContentDescription("");
lineChart.setNoDataText(getString(R.string.noChartDataString));
lineChart.setNoDataTextColor(R.color.darkRed);
lineChart.setOnChartValueSelectedListener(this);
lineChart.setOnChartGestureListener(new OnChartGestureListener() {
@Override
public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
YAxis yAxis = lineChart.getAxisLeft();
// Allow scrolling in the right and left margins
if (me.getX() > yAxis.getLongestLabel().length() * yAxis.getTextSize() && me.getX() < displayWidth - lineChart.getViewPortHandler().offsetRight()) {
viewPager.setPagingEnabled(false);
nestedScrollView.setScrollingEnabled(false);
}
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
viewPager.setPagingEnabled(true);
nestedScrollView.setScrollingEnabled(true);
}
@Override
public void onChartLongPressed(MotionEvent me) {
}
@Override
public void onChartDoubleTapped(MotionEvent me) {
}
@Override
public void onChartSingleTapped(MotionEvent me) {
}
@Override
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
}
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
}
@Override
public void onChartTranslate(MotionEvent me, float dX, float dY) {
}
});
}
use of com.github.mikephil.charting.components.YAxis in project AmazMod by edotassi.
the class BatteryChartCard method updateChart.
private void updateChart() {
final List<Entry> yValues = new ArrayList<Entry>();
final List<Integer> colors = new ArrayList<>();
final int days = PreferenceManager.getInt(getContext(), Constants.PREFERENCE_BATTERY_CHART_RANGE, 5);
Calendar calendar = Calendar.getInstance();
long highX = calendar.getTimeInMillis();
calendar.add(Calendar.DATE, -1 * days);
long lowX = calendar.getTimeInMillis();
List<BatteryRead> batteryReadList = SQLite.select().from(BatteryRead.class).where(BatteryRead_Table.date.greaterThan(lowX)).queryList();
BatteryRead prevRead = null;
for (int i = 0; i < batteryReadList.size(); i++) {
BatteryRead read = batteryReadList.get(i);
if ((read.getLevel() > 0) && ((prevRead == null) || (read.getLevel() != prevRead.getLevel()))) {
Entry entry = new Entry(read.getDate(), read.getLevel());
yValues.add(entry);
colors.add(Color.parseColor(read.isCharging() ? "#00E676" : "#3F51B5"));
}
prevRead = read;
}
if (yValues.size() == 0) {
return;
}
LineDataSet lineDataSet = new LineDataSet(yValues, "Battery");
lineDataSet.setLineWidth(1.5f);
lineDataSet.setDrawCircleHole(false);
lineDataSet.setDrawCircles(false);
lineDataSet.setDrawValues(false);
Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fade_blue_battery);
lineDataSet.setDrawFilled(true);
lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
lineDataSet.setFillDrawable(drawable);
lineDataSet.setColors(colors);
lineDataSet.setMode(LineDataSet.Mode.LINEAR);
lineDataSet.setCubicIntensity(0.05f);
Description description = new Description();
description.setText("");
chart.setDescription(description);
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setLabelRotationAngle(-45);
xAxis.setTextSize(8);
xAxis.setAxisMinimum(lowX);
xAxis.setAxisMaximum(highX);
final Calendar now = Calendar.getInstance();
final SimpleDateFormat simpleDateFormatHours = new SimpleDateFormat("HH");
final SimpleDateFormat simpleDateFormatHoursMinutes = new SimpleDateFormat("HH:mm");
final SimpleDateFormat simpleDateFormatDateMonth = new SimpleDateFormat("dd/MM");
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis((long) value);
Date date = calendar.getTime();
if ((days > 1) || (now.get(Calendar.DATE) != calendar.get(Calendar.DATE))) {
int minutes = calendar.get(Calendar.MINUTE);
if (minutes > 30) {
calendar.add(Calendar.HOUR, 1);
}
return simpleDateFormatHours.format(date) + "\n" + simpleDateFormatDateMonth.format(date);
} else {
return simpleDateFormatHoursMinutes.format(calendar.getTime()) + "\n" + simpleDateFormatDateMonth.format(calendar.getTime());
}
}
});
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setDrawAxisLine(true);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(true);
leftAxis.setAxisMinimum(0);
leftAxis.setAxisMaximum(100);
chart.getAxisRight().setEnabled(false);
chart.getLegend().setEnabled(false);
chart.setTouchEnabled(false);
chart.setXAxisRenderer(new CustomXAxisRenderer(chart.getViewPortHandler(), chart.getXAxis(), chart.getTransformer(YAxis.AxisDependency.LEFT)));
LineData lineData = new LineData(lineDataSet);
chart.setData(lineData);
chart.invalidate();
}
use of com.github.mikephil.charting.components.YAxis in project Osmand by osmandapp.
the class GpxUiHelper method setupGPXChart.
public static void setupGPXChart(OsmandApplication ctx, LineChart mChart, int yLabelsCount) {
OsmandSettings settings = ctx.getSettings();
boolean light = settings.isLightContent();
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mChart.setHardwareAccelerationEnabled(false);
} else {
mChart.setHardwareAccelerationEnabled(true);
}
mChart.setTouchEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setPinchZoom(true);
mChart.setScaleYEnabled(false);
mChart.setAutoScaleMinMaxEnabled(true);
mChart.setDrawBorders(false);
mChart.getDescription().setEnabled(false);
mChart.setMaxVisibleValueCount(10);
mChart.setMinOffset(0f);
mChart.setDragDecelerationEnabled(false);
mChart.setExtraTopOffset(24f);
mChart.setExtraBottomOffset(16f);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
GPXMarkerView mv = new GPXMarkerView(mChart.getContext());
// For bounds control
mv.setChartView(mChart);
// Set the marker to the chart
mChart.setMarker(mv);
mChart.setDrawMarkers(true);
XAxis xAxis = mChart.getXAxis();
xAxis.setDrawAxisLine(false);
xAxis.setDrawGridLines(true);
xAxis.setGridLineWidth(1.5f);
xAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_black_grid));
xAxis.enableGridDashedLine(25f, Float.MAX_VALUE, 0f);
xAxis.setPosition(BOTTOM);
xAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
YAxis yAxis = mChart.getAxisLeft();
yAxis.enableGridDashedLine(10f, 5f, 0f);
yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.divider_color));
yAxis.setDrawAxisLine(false);
yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
yAxis.setXOffset(16f);
yAxis.setYOffset(-6f);
yAxis.setLabelCount(yLabelsCount);
yAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
yAxis = mChart.getAxisRight();
yAxis.enableGridDashedLine(10f, 5f, 0f);
yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.divider_color));
yAxis.setDrawAxisLine(false);
yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
yAxis.setXOffset(16f);
yAxis.setYOffset(-6f);
yAxis.setLabelCount(yLabelsCount);
yAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
yAxis.setEnabled(false);
Legend legend = mChart.getLegend();
legend.setEnabled(false);
}
use of com.github.mikephil.charting.components.YAxis in project Osmand by osmandapp.
the class GpxUiHelper method createGPXSlopeDataSet.
public static OrderedLineDataSet createGPXSlopeDataSet(OsmandApplication ctx, LineChart mChart, GPXTrackAnalysis analysis, GPXDataSetAxisType axisType, List<Entry> eleValues, boolean useRightAxis, boolean drawFilled) {
if (axisType == GPXDataSetAxisType.TIME) {
return null;
}
OsmandSettings settings = ctx.getSettings();
boolean light = settings.isLightContent();
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
final float convEle = useFeet ? 3.28084f : 1.0f;
final float totalDistance = analysis.totalDistance;
XAxis xAxis = mChart.getXAxis();
float divX = setupXAxisDistance(ctx, xAxis, analysis.totalDistance);
final String mainUnitY = "%";
YAxis yAxis;
if (useRightAxis) {
yAxis = mChart.getAxisRight();
yAxis.setEnabled(true);
} else {
yAxis = mChart.getAxisLeft();
}
yAxis.setTextColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_green_label));
yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_green_grid));
yAxis.setGranularity(1f);
yAxis.resetAxisMinimum();
yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return (int) value + " " + mainUnitY;
}
});
List<Entry> values;
if (eleValues == null) {
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f);
} else {
values = new ArrayList<>(eleValues.size());
for (Entry e : eleValues) {
values.add(new Entry(e.getX() * divX, e.getY() / convEle));
}
}
if (values == null || values.size() == 0) {
if (useRightAxis) {
yAxis.setEnabled(false);
}
return null;
}
int lastIndex = values.size() - 1;
double STEP = 5;
double[] calculatedDist = new double[(int) (totalDistance / STEP) + 1];
double[] calculatedH = new double[(int) (totalDistance / STEP) + 1];
int nextW = 0;
for (int k = 0; k < calculatedDist.length; k++) {
if (k > 0) {
calculatedDist[k] = calculatedDist[k - 1] + STEP;
}
while (nextW < lastIndex && calculatedDist[k] > values.get(nextW).getX()) {
nextW++;
}
double pd = nextW == 0 ? 0 : values.get(nextW - 1).getX();
double ph = nextW == 0 ? values.get(0).getY() : values.get(nextW - 1).getY();
calculatedH[k] = ph + (values.get(nextW).getY() - ph) / (values.get(nextW).getX() - pd) * (calculatedDist[k] - pd);
}
double SLOPE_PROXIMITY = 100;
if (totalDistance - SLOPE_PROXIMITY < 0) {
if (useRightAxis) {
yAxis.setEnabled(false);
}
return null;
}
double[] calculatedSlopeDist = new double[(int) ((totalDistance - SLOPE_PROXIMITY) / STEP) + 1];
double[] calculatedSlope = new double[(int) ((totalDistance - SLOPE_PROXIMITY) / STEP) + 1];
int index = (int) ((SLOPE_PROXIMITY / STEP) / 2);
for (int k = 0; k < calculatedSlopeDist.length; k++) {
calculatedSlopeDist[k] = calculatedDist[index + k];
calculatedSlope[k] = (calculatedH[2 * index + k] - calculatedH[k]) * 100 / SLOPE_PROXIMITY;
if (Double.isNaN(calculatedSlope[k])) {
calculatedSlope[k] = 0;
}
}
List<Entry> slopeValues = new ArrayList<>(calculatedSlopeDist.length);
float prevSlope = -80000;
float slope;
float x;
float lastXSameY = 0;
boolean hasSameY = false;
Entry lastEntry = null;
lastIndex = calculatedSlopeDist.length - 1;
for (int i = 0; i < calculatedSlopeDist.length; i++) {
x = (float) calculatedSlopeDist[i] / divX;
slope = (float) calculatedSlope[i];
if (prevSlope != -80000) {
if (prevSlope == slope && i < lastIndex) {
hasSameY = true;
lastXSameY = x;
continue;
}
if (hasSameY) {
slopeValues.add(new Entry(lastXSameY, lastEntry.getY()));
}
hasSameY = false;
}
prevSlope = slope;
lastEntry = new Entry(x, slope);
slopeValues.add(lastEntry);
}
OrderedLineDataSet dataSet = new OrderedLineDataSet(slopeValues, "", GPXDataSetType.SLOPE, axisType);
dataSet.divX = divX;
dataSet.units = mainUnitY;
dataSet.setColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_green));
dataSet.setLineWidth(1f);
if (drawFilled) {
dataSet.setFillAlpha(128);
dataSet.setFillColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_green));
dataSet.setDrawFilled(true);
} else {
dataSet.setDrawFilled(false);
}
dataSet.setDrawValues(false);
dataSet.setValueTextSize(9f);
dataSet.setFormLineWidth(1f);
dataSet.setFormSize(15.f);
dataSet.setDrawCircles(false);
dataSet.setDrawCircleHole(false);
dataSet.setHighlightEnabled(true);
dataSet.setDrawVerticalHighlightIndicator(true);
dataSet.setDrawHorizontalHighlightIndicator(false);
dataSet.setHighLightColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
/*
dataSet.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return dataProvider.getYChartMin();
}
});
*/
if (useRightAxis) {
dataSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
}
return dataSet;
}
use of com.github.mikephil.charting.components.YAxis in project MPAndroidChart by PhilJay.
the class RadarChartActivity 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_radarchart);
setTitle("RadarChartActivity");
chart = findViewById(R.id.chart1);
chart.setBackgroundColor(Color.rgb(60, 65, 82));
chart.getDescription().setEnabled(false);
chart.setWebLineWidth(1f);
chart.setWebColor(Color.LTGRAY);
chart.setWebLineWidthInner(1f);
chart.setWebColorInner(Color.LTGRAY);
chart.setWebAlpha(100);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
// For bounds control
mv.setChartView(chart);
// Set the marker to the chart
chart.setMarker(mv);
setData();
chart.animateXY(1400, 1400, Easing.EaseInOutQuad);
XAxis xAxis = chart.getXAxis();
xAxis.setTypeface(tfLight);
xAxis.setTextSize(9f);
xAxis.setYOffset(0f);
xAxis.setXOffset(0f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
private final String[] mActivities = new String[] { "Burger", "Steak", "Salad", "Pasta", "Pizza" };
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mActivities[(int) value % mActivities.length];
}
});
xAxis.setTextColor(Color.WHITE);
YAxis yAxis = chart.getYAxis();
yAxis.setTypeface(tfLight);
yAxis.setLabelCount(5, false);
yAxis.setTextSize(9f);
yAxis.setAxisMinimum(0f);
yAxis.setAxisMaximum(80f);
yAxis.setDrawLabels(false);
Legend l = chart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setTypeface(tfLight);
l.setXEntrySpace(7f);
l.setYEntrySpace(5f);
l.setTextColor(Color.WHITE);
}
Aggregations