private void createChart(View v) { BarChart chart = (BarChart) v.findViewById(R.id.barChart); chart.clear(); PSDatePickerView datePickerView = (PSDatePickerView) v.findViewById(R.id.date_picker_view); PSUserDataCollection dataCollection = PSDataStore.getInstance().getUserDataCollection(); ArrayList<BarEntry> entriesAgg = new ArrayList<BarEntry>(); ArrayList<String> xVals = new ArrayList<String>(); int idx = 0; for (Calendar cur = (Calendar) datePickerView.getStartDate().clone(); PSUtil.beforeCalender(cur, datePickerView.getEndDate()); cur.add(Calendar.DATE, 1)) { PSDailyData dailyData = dataCollection.getDailyData(cur.getTimeInMillis()); BarEntry ent = null; if (dailyData != null) { ent = new BarEntry(dailyData.getFormula(), idx, dailyData); } if (ent != null) { entriesAgg.add(ent); } xVals.add(PSUtil.weekDays[idx]); idx++; } BarDataSet setAgg = new BarDataSet(entriesAgg, PSDataStore.getInstance().getUser().getName()); setAgg.setAxisDependency(YAxis.AxisDependency.LEFT); setAgg.setColor(getResources().getColor(R.color.ps_blue_sky)); ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); dataSets.add(setAgg); // BarData BarData data = new BarData(xVals, dataSets); chart.setData(data); // Config chart chart.setDescription(""); chart.setDrawHighlightArrow(true); // Config axises YAxis leftAxis = chart.getAxisLeft(); YAxis rightAxis = chart.getAxisRight(); leftAxis.setDrawGridLines(false); rightAxis.setDrawGridLines(false); // Config limit line LimitLine ll = new LimitLine(60f); ll.setLineColor(Color.CYAN); ll.setLineWidth(1f); leftAxis.removeAllLimitLines(); leftAxis.addLimitLine(ll); // Config marker PSDailyDataMarkerView markerView = new PSDailyDataMarkerView(v.getContext(), R.layout.ps_daily_data_marker_view); chart.setMarkerView(markerView); // Legend Legend l = chart.getLegend(); l.setEnabled(false); // Show data chart.animateY(600); }
@Override protected void setupChart() { super.setupChart(); lineChart.setData(setupTheeComponentData("X", "Y", "Z")); lineChart.getLegend().setEnabled(true); lineChart.getLegend().setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); LimitLine line = new LimitLine(FeatureAcceleration.DATA_MIN, "timestamp (ms)"); line.setLineColor(Color.BLACK); line.setLineWidth(1f); line.setTextColor(Color.BLACK); line.setTextSize(12f); line.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_TOP); lineChart.getAxisLeft().addLimitLine(line); }