public void styleLineChart(LineChart chart) { chart.setGridBackgroundColor(0x00000000); chart.getAxisRight().setDrawLabels(false); chart.getXAxis().setDrawAxisLine(false); chart.getXAxis().setDrawGridLines(false); chart.getXAxis().setAvoidFirstLastClipping(true); chart.getLegend().setEnabled(false); chart.getAxisLeft().setDrawAxisLine(false); chart.getAxisRight().setDrawAxisLine(false); chart.invalidate(); }
/** * Refreshs a chart. * * @param chart * @param chartDataSets */ public void refreshChart(LineChart chart, ArrayList<LineDataSet> chartDataSets) { // Populates X List. // Identifies the biggets dataset. int maxSize = 0; for (LineDataSet dataSet : chartDataSets) if (dataSet.getEntryCount() > maxSize) maxSize = dataSet.getEntryCount(); ArrayList<String> xVals = new ArrayList<String>(); while (xVals.size() < maxSize) xVals.add((xVals.size() + 1) + ""); LineData chartData = new LineData(xVals, chartDataSets); chart.setData(chartData); chart.notifyDataSetChanged(); chart.invalidate(); }
public void formatChartDataNoThread( final List<BankModel> posts, final LineChart chart, final Context context) { final ArrayList<String> cashXVals = new ArrayList<String>(); final ArrayList<Entry> cashYVals1 = new ArrayList<Entry>(); final ArrayList<Entry> credYVals1 = new ArrayList<Entry>(); addXandYCoords(posts, cashXVals, cashYVals1, credYVals1); LineDataSet set = new LineDataSet(cashYVals1, "DataSet 1"); LineDataSet set2 = new LineDataSet(credYVals1, "DataSet 2"); formatDataSet(set, Color.parseColor("#4CAF50")); formatDataSet(set2, Color.parseColor("#F44336")); ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); dataSets.add(set); dataSets.add(set2); LineData data = new LineData(cashXVals, dataSets); CustomMarkerView mv = new CustomMarkerView(context, R.layout.marker_view); chart.setTouchEnabled(true); chart.setMarkerView(mv); chart.setData(data); chart.setDescription(""); chart.invalidate(); }
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LineView = inflater.inflate(R.layout.analysis_bar, container, false); initView(); // no description text mChart.setDescription(""); // enable value highlighting mChart.setHighlightEnabled(true); // enable touch gestures mChart.setTouchEnabled(true); // enable scaling and dragging mChart.setDragEnabled(true); mChart.setScaleEnabled(true); // if disabled, scaling can be done on x- and y-axis separately mChart.setPinchZoom(false); mChart.setDrawGridBackground(true); // tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); XAxis x = mChart.getXAxis(); // x.setTypeface(tf); x.setEnabled(true); YAxis y = mChart.getAxisLeft(); // y.setTypeface(tf); y.setLabelCount(5); y.setEnabled(true); mChart.getAxisRight().setEnabled(true); // add data catchData(); Date dt = new Date(); SimpleDateFormat matter1 = new SimpleDateFormat("dd"); int days = Integer.parseInt(matter1.format(dt)); log.e("days = " + days); setData(days - 9, 10, 100); mChart.getLegend().setEnabled(true); mChart.animateXY(2000, 2000); // dont forget to refresh the drawing /*ArrayList<LineDataSet> sets = (ArrayList<LineDataSet>) mChart.getData() .getDataSets(); for (LineDataSet set : sets) { if (set.isDrawCubicEnabled()) set.setDrawCubic(false); else set.setDrawCubic(true); }*/ mChart.invalidate(); return LineView; }
private void drawChart() { BPRecord[] recs = mRecords; LineChart chart = (LineChart) findViewById(R.id.chart); ArrayList<Entry> valsHigh = new ArrayList<Entry>(); ArrayList<Entry> valsLow = new ArrayList<Entry>(); // ArrayList<Entry> heartRate = new ArrayList<Entry>(); // ArrayList<Entry> o2Index = new ArrayList<Entry>(); // ArrayList<Entry> avgArtP = new ArrayList<Entry>(); ArrayList<String> xVals = new ArrayList<String>(); Date firstTime = null; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat f2 = new SimpleDateFormat("MM/dd HH:mm"); for (int i = 0; i < recs.length; ++i) { BPRecord rec = recs[i]; int x = 0; // minutes from first data Date time = new Date(); try { time = f.parse(rec.dateTime); } catch (ParseException ex) { Log.d("GetBPDate", "Exception:" + ex.toString()); continue; } if (firstTime == null) { firstTime = time; } else { x = (int) ((time.getTime() - firstTime.getTime()) / 60000); } x = i; xVals.add(f2.format(time)); valsHigh.add(new Entry(rec.systolic, x)); valsLow.add(new Entry(rec.diastolic, x)); // heartRate.add(new Entry(rec.heartRate,x)); // avgArtP.add(new Entry(rec.avg_art_pressure,x)); // o2Index.add(new Entry(rec.o2Index/100,x)); } String hp = getResources().getString(R.string.hightPressure); String lp = getResources().getString(R.string.lowPressure); /* String hr = getResources().getString(R.string.heartBeatLabel); String avgAP = getResources().getString(R.string.average_artery_pressure); String o2 = getResources().getString(R.string.O2Index); */ LineDataSet setHigh = new LineDataSet(valsHigh, hp); setHigh.setAxisDependency(YAxis.AxisDependency.LEFT); setHigh.setDrawCircles(false); setHigh.setColor(Color.RED); setHigh.setValueFormatter(new IntFormatter()); setHigh.setValueTextSize(10); LineDataSet setLow = new LineDataSet(valsLow, lp); setLow.setAxisDependency(YAxis.AxisDependency.LEFT); setLow.setColor(Color.BLUE); setLow.setDrawCircles(false); setLow.setValueFormatter(new IntFormatter()); setLow.setValueTextSize(10); /* LineDataSet setHr = new LineDataSet(heartRate, hr); setHr.setAxisDependency(YAxis.AxisDependency.LEFT); setHr.setColor(Color.GREEN); setHr.setDrawCircles(false); setHr.setValueFormatter(new IntFormatter()); setHr.setValueTextSize(10); LineDataSet setAAP = new LineDataSet(avgArtP, avgAP); setAAP.setAxisDependency(YAxis.AxisDependency.LEFT); setAAP.setColor(Color.DKGRAY); setAAP.setDrawCircles(false); setAAP.setValueFormatter(new IntFormatter()); setAAP.setValueTextSize(10); LineDataSet setO2 = new LineDataSet(o2Index, o2); setO2.setAxisDependency(YAxis.AxisDependency.LEFT); setO2.setColor(Color.CYAN); setO2.setDrawCircles(false); setO2.setValueFormatter(new IntFormatter()); setO2.setValueTextSize(10); */ ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); dataSets.add(setHigh); dataSets.add(setLow); /* dataSets.add(setHr); dataSets.add(setAAP); dataSets.add(setO2); */ /* xVals.add("12-15"); xVals.add("12-17"); xVals.add("12-18"); xVals.add("12-20"); xVals.add("12-21"); xVals.add("12-22"); xVals.add("12-23"); xVals.add("12-24"); */ LineData data = new LineData(xVals, dataSets); // chart.setGridBackgroundColor(Color.BLACK); // chart.getLegend().setEnabled(false); chart.setData(data); chart.setDescription(getResources().getString(R.string.blood_pressure)); chart.invalidate(); // refresh }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_status, container, false); // TODO Need lot of design changes in chart // TODO Have to update LineChart with CombineChart to display LineChart with BarChart mChart = (LineChart) view.findViewById(R.id.chartInsight); mChart.setDescription(""); mChart.setBackgroundColor(Color.WHITE); mChart.setDrawGridBackground(false); LineData d = new LineData(); ArrayList<Entry> entries = new ArrayList<>(); for (int index = 0; index < 12; index++) entries.add(new Entry(getRandom(25, 10), index)); LineDataSet set = new LineDataSet(entries, "DataSet1"); set.setColor(Color.rgb(240, 238, 70)); set.setLineWidth(2.5f); set.setCircleColor(Color.rgb(240, 238, 70)); set.setCircleSize(5f); set.setFillColor(Color.rgb(240, 238, 70)); set.setDrawCubic(true); set.setDrawValues(true); set.setValueTextSize(10f); set.setValueTextColor(Color.rgb(240, 238, 70)); for (int index = 0; index < 12; index++) entries.add(new Entry(getRandom(25, 10), index)); LineDataSet set2 = new LineDataSet(entries, "DataSet2"); set.setColor(Color.rgb(240, 238, 70)); set.setLineWidth(2.5f); set.setCircleColor(Color.rgb(240, 238, 70)); set.setCircleSize(5f); set.setFillColor(Color.rgb(240, 238, 70)); set.setDrawCubic(true); set.setDrawValues(true); set.setValueTextSize(10f); set.setValueTextColor(Color.rgb(240, 238, 70)); set.setAxisDependency(YAxis.AxisDependency.LEFT); d.addDataSet(set); d.addDataSet(set2); mChart.setData(d); mChart.setDescription("Fuel Insight"); mChart.animateXY(2000, 2000); mChart.invalidate(); // String[] projection = { FuelContract.COLUMN_AMOUNT, FuelContract.COLUMN_ID }; // Cursor fuelData = // inflater.getContext().getContentResolver().query(FuelProvider.FUEL_CONTENT_URI, projection, // null, null, null); // while (fuelData.getCount()!=0) { // fuelData.moveToNext(); // Log.i("FuelData", "ID: " + fuelData.getString(1) + " Amount: " + // fuelData.getString(0)); // } return view; }