private void addEntry() { LineData data = mChart.getData(); int year = 2015; if (data != null) { LineDataSet set = data.getDataSetByIndex(0); if (set == null) { set = createSet(); data.addDataSet(set); } // data.addXValue(mMonths[data.getXValCount() % 12] + " " + (year + // data.getXValCount() /12)); // data.addEntry(new Entry((float) (Math.random() * 40) + 30f, set.getEntryCount(), // 0)); mChart.notifyDataSetChanged(); mChart.setVisibleXRangeMaximum(120); mChart.moveViewToX(data.getXValCount() - 121); } }
@SuppressWarnings("ButterKnifeInjectNotCalled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setup(mChart); mChart.getAxisLeft().setAxisMaximum(150f); mChart.getAxisLeft().setAxisMinimum(0f); mChart.getAxisLeft().setDrawGridLines(false); mChart.getXAxis().setDrawGridLines(false); }
/** * 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(); }
private void setData(int count, float range) { ArrayList<String> xVals = new ArrayList<String>(); for (int i = 0; i < count; i++) { xVals.add((i % 30) + "/" + (i % 12) + "/14"); } ArrayList<Entry> yVals = new ArrayList<Entry>(); for (int i = 0; i < count; i++) { float mult = (range + 1); float val = (float) (Math.random() * mult) + 3; // + (float) // ((mult * // 0.1) / 10); yVals.add(new Entry(val, i)); } // create a dataset and give it a type LineDataSet set1 = new LineDataSet(yVals, "DataSet 1"); set1.setLineWidth(1.5f); set1.setCircleSize(4f); // create a data object with the datasets LineData data = new LineData(xVals, set1); // set data mChart.setData(data); }
private void setData(int start, int count, float range) { ArrayList<String> xVals = new ArrayList<String>(); for (int i = 0; i < count; i++) { xVals.add((start + i) + "日"); } ArrayList<Entry> vals1 = new ArrayList<Entry>(); for (int i = 0; i < count; i++) { vals1.add(new Entry(TurnControl.PunchPerDay[9 - i], i)); } // create a dataset and give it a type LineDataSet set1 = new LineDataSet(vals1, "近期打卡情况"); set1.setDrawCubic(true); set1.setCubicIntensity(0.2f); set1.setDrawFilled(true); set1.setDrawCircles(true); set1.setLineWidth(2f); set1.setCircleSize(5f); set1.setHighLightColor(Color.rgb(244, 117, 117)); set1.setColor(Color.rgb(104, 241, 175)); set1.setFillColor(ColorTemplate.getHoloBlue()); // create a data object with the datasets LineData data = new LineData(xVals, set1); data.setValueTypeface(tf); data.setValueTextSize(9f); data.setDrawValues(false); // set data mChart.setData(data); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); // défini un nouveau format de date en string ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_statistics_linechart, container, false); LineChart chart = (LineChart) rootView.findViewById(R.id.firstChart); chart.setLogEnabled(true); chart.setNoDataTextDescription(getString(R.string.no_data)); ArrayList<DrinkIncome> incomesByDrink = getIncomes(); ArrayList<Entry> Income1 = new ArrayList<Entry>(); // creation d'un arrayList d'entrées pour le tableau ArrayList<Entry[]> drink2 = new ArrayList<Entry[]>(); ArrayList<Entry> drink3 = new ArrayList<Entry>(); ArrayList<Entry> drink4 = new ArrayList<Entry>(); ArrayList<Entry> drink5 = new ArrayList<Entry>(); ArrayList<String> xVals = new ArrayList<String>(); // creation d'une arrayList pour les valeurs des abscisses Iterator<DrinkIncome> it = incomesByDrink.iterator(); for (int i = 0; it.hasNext() && i < 5; i++) { DrinkIncome s = it.next(); Entry element = new Entry(s.getIncome(), i); Income1.add(element); // xVals.add(df.format(s.getDateOrder())); xVals.add("J-" + i); } LineDataSet setBestDrinks = new LineDataSet(Income1, getString(R.string.daily_incomes)); setBestDrinks.setDrawFilled(true); setBestDrinks.setColors( new int[] {R.color.blue1, R.color.blue2, R.color.blue3, R.color.blue1}, rootView.getContext()); ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); dataSets.add(setBestDrinks); LineData data = new LineData(xVals, dataSets); chart.setData(data); return rootView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_realm_wiki); lineChart = (LineChart) findViewById(R.id.lineChart); barChart = (BarChart) findViewById(R.id.barChart); setup(lineChart); setup(barChart); lineChart.getAxisLeft().setDrawGridLines(false); lineChart.getXAxis().setDrawGridLines(false); barChart.getAxisLeft().setDrawGridLines(false); barChart.getXAxis().setDrawGridLines(false); }
private void loadData(boolean drawLast) { ChartCollection collection = fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection(); if (collection != null) { int size = collection.size(); if (size > 0) { List<Entry> entries = new ArrayList<>(); List<String> xVals = new ArrayList<>(); ChartData data = collection.getCharData(size - 1); Map<Double, Double> values = data.getData(); List<Double> keyList = new ArrayList<>(); keyList.addAll(values.keySet()); Collections.sort(keyList); for (Double x : keyList) { Number numX = x; int intX = numX.intValue(); xVals.add(String.valueOf(x)); double value = values.get(x); Number num = value; float val = num.floatValue(); Entry entry = new Entry(val, intX); entries.add(entry); } LineDataSet dataSet = new LineDataSet(entries, "Dados"); dataSet.setDrawCircleHole(false); dataSet.setDrawCircles(false); LineData chartData = new LineData(xVals, dataSet); chart.setData(chartData); totalGraphs = size; if (drawLast) { currentGraph = totalGraphs; } else { if (currentGraph < 1 || currentGraph > size) { currentGraph = totalGraphs; } } mainHandler.post( new Runnable() { @Override public void run() { chart.notifyDataSetChanged(); chart.invalidate(); txtTotal.setText(String.valueOf(totalGraphs)); txtCurrent.setText(String.valueOf(currentGraph)); } }); } } }
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(); }
private void addEntry() { LineData data = mLineChart.getData(); if (data != null) { LineDataSet set = data.getDataSetByIndex(0); if (set == null) { set = createSet(); data.addDataSet(set); } // add a new random value float a = r.nextFloat() * (2.00f + 2.00f) - 2.0f; System.out.println(a); data.addXValue(""); data.addEntry(new Entry(a, set.getEntryCount()), 0); mLineChart.notifyDataSetChanged(); mLineChart.setVisibleXRange(6, 0); mLineChart.moveViewToX(data.getXValCount() - 7); } }
private void setData() { // LINE-CHART RealmResults<Score> results = mRealm.allObjects(Score.class); RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "totalScore", "scoreNr"); lineDataSet.setDrawCubic(false); lineDataSet.setLabel("Realm LineDataSet"); lineDataSet.setDrawCircleHole(false); lineDataSet.setColor(ColorTemplate.rgb("#FF5722")); lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722")); lineDataSet.setLineWidth(1.8f); lineDataSet.setCircleSize(3.6f); ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); dataSets.add(lineDataSet); RealmLineData lineData = new RealmLineData(results, "playerName", dataSets); styleData(lineData); // set data lineChart.setData(lineData); lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart); // BAR-CHART RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "totalScore", "scoreNr"); barDataSet.setColors(new int[] {ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4")}); barDataSet.setLabel("Realm BarDataSet"); ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>(); barDataSets.add(barDataSet); RealmBarData barData = new RealmBarData(results, "playerName", barDataSets); styleData(barData); barChart.setData(barData); barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart); }
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(); }
private void setData() { RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll(); RealmLineDataSet<RealmDemoData> set = new RealmLineDataSet<RealmDemoData>(result, "xValue", "yValue"); set.setDrawCubic(false); set.setLabel("Realm LineDataSet"); set.setDrawCircleHole(false); set.setColor(ColorTemplate.rgb("#FF5722")); set.setCircleColor(ColorTemplate.rgb("#FF5722")); set.setLineWidth(1.8f); // set.setCircleSize(3.6f); // TODO ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); dataSets.add(set); // add the dataset // create a data object with the dataset list LineData data = new LineData(dataSets); styleData(data); // set data mChart.setData(data); mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart); }
/** * There is one chart for each signal type. Returns the chart component of a specific signal type. * * @return */ public LineChart getChart(String signalTypeId) { if (!charts.containsKey(signalTypeId)) { // Create a chart component // chart = (LineChart) findViewById(R.id.chart); final LineChart chart = new LineChart(this); // chart.setUnit("Db"); chart.setUnit(""); // chart.setDrawUnitsInChart(true); chart.setDrawYValues(false); chart.setDrawBorder(false); chart.setTouchEnabled(true); chart.setDragEnabled(true); chart.setNoDataTextDescription("No data gathered."); chart.setDescription("Samples"); chart.setPinchZoom(true); // if disabled, scaling can be done on x- and y-axis separately // set an alternative background color // mChart.setBackgroundColor(Color.GRAY) // Creates a chart tab. // http://www.java2s.com/Code/Android/UI/DynamicTabDemo.htm // http://www.java2s.com/Code/Android/UI/UsingatabcontentfactoryforthecontentviaTabHostTabSpecsetContentandroidwidgetTabHostTabContentFactory.htm TabHost.TabSpec spec = tabHost.newTabSpec(signalTypeId); spec.setIndicator(signalTypeId); spec.setContent( new TabHost.TabContentFactory() { public View createTabContent(String tag) { return chart; } }); tabHost.addTab(spec); // addContentToTab(tabHost.getChildCount(), chart); charts.put(signalTypeId, chart); tabHost.invalidate(); } return charts.get(signalTypeId); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.kommfort, container, false); RelativeLayout relativ = (RelativeLayout) rootView.findViewById(R.id.bak); mLineChart = (LineChart) relativ.findViewById(R.id.linechartkommfort); mLineChart.setOnChartValueSelectedListener(this); // no description text mLineChart.setDescription("Beschleunigungskraefte"); mLineChart.setNoDataTextDescription("You need to provide data for the chart."); // enable highlighting mLineChart.setHighlightEnabled(true); // enable touch gestures mLineChart.setTouchEnabled(true); // enable scaling and dragging mLineChart.setDragEnabled(true); mLineChart.setScaleEnabled(true); mLineChart.setDrawGridBackground(false); // if disabled, scaling can be done on x- and y-axis separately mLineChart.setPinchZoom(true); // set an alternative background color mLineChart.setBackgroundColor(Color.WHITE); LineData data = new LineData(); data.setValueTextColor(Color.BLACK); // add empty data mLineChart.setData(data); // get the legend (only possible after setting data) Legend l = mLineChart.getLegend(); // modify the legend ... // l.setPosition(LegendPosition.LEFT_OF_CHART); l.setForm(Legend.LegendForm.LINE); l.setTextColor(Color.BLACK); XAxis xl = mLineChart.getXAxis(); xl.setTextColor(Color.BLACK); xl.setDrawGridLines(false); xl.setAvoidFirstLastClipping(true); YAxis leftAxis = mLineChart.getAxisLeft(); leftAxis.setTextColor(Color.BLACK); leftAxis.setAxisMaxValue(2f); leftAxis.setAxisMinValue(-2f); leftAxis.setStartAtZero(false); leftAxis.setDrawGridLines(true); YAxis rightAxis = mLineChart.getAxisRight(); rightAxis.setEnabled(false); Button zukamm = (Button) rootView.findViewById(R.id.butonzumkreis); // TextView zubesh=(TextView) rootView.findViewById(R.id.zubeschleunigungskraefte); // Layout button=(Layout) rootView.findViewById(R.id.); zukamm.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), KammsherKreis.class); Kommfort.this.startActivity(intent); } }); /** * zubesh.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { * Intent myIntent = new Intent(getActivity(), Beschleunigungskraefte.class); * getActivity().startActivityForResult(myIntent,100); } }); */ return rootView; }
public void drawLineChart( View v, int averageCrowdValue, List<Integer> todaysCrowdValues, List<Integer> rodCrowdValues) { /* Create data entries1 and labels for todaysCrowd Values*/ ArrayList<Entry> entries1 = new ArrayList<>(); ArrayList<String> labels = new ArrayList<>(); for (int hour = 0; hour < todaysCrowdValues.size(); hour++) { entries1.add(new Entry(todaysCrowdValues.get(hour), hour)); labels.add("" + hour); } /* Create data entries2 and labels for rodCrowdValues Values*/ ArrayList<Entry> entries2 = new ArrayList<>(); for (int hour = 0; hour < rodCrowdValues.size(); hour++) { entries2.add(new Entry(rodCrowdValues.get(hour), hour + todaysCrowdValues.size())); labels.add("" + (hour + todaysCrowdValues.size())); } /* Create dataentires for averageCrowdValue */ ArrayList<Entry> entries3 = new ArrayList<>(); entries3.add(new Entry(averageCrowdValue, 0)); entries3.add(new Entry(averageCrowdValue, 23)); // Create dataset from data entries1 LineDataSet dataset1 = new LineDataSet(entries1, "Today's Crowd"); LineDataSet dataset2 = new LineDataSet(entries2, "Predicted Crowd"); LineDataSet dataset3 = new LineDataSet(entries3, "Average Crowd"); // Set the color for this dataset dataset1.setColor(Color.rgb(0, 37, 76)); // GT Navy dataset2.setColor(Color.rgb(238, 178, 17)); // Buzz Gold dataset3.setColor(Color.rgb(197, 147, 83)); // GT Gold // Aggregate all data sets ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); dataSets.add(dataset1); dataSets.add(dataset2); dataSets.add(dataset3); /* Create the chart */ LineChart chart = (LineChart) v.findViewById(R.id.chart); // Hide Labels and grid lines from x axis chart.getXAxis().setDrawGridLines(false); chart.getXAxis().setDrawLabels(false); // Hide labels and grid lines from y axis chart.getAxisLeft().setDrawGridLines(false); chart.getAxisLeft().setDrawLabels(false); chart.getAxisRight().setDrawGridLines(false); chart.getAxisRight().setDrawLabels(false); // Dont label each node on graph chart.setDrawMarkerViews(false); LineData data = new LineData(labels, dataSets); chart.setData(data); chart.setDescription("Today's Crowd"); // animations chart.animateY(1000); }
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; }
public Bitmap createGraphBitmap(List<BankModel> posts, Context context, int width, int height) { LineChart lineChart = new LineChart(context); lineChart.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); lineChart.setLayoutParams(new LinearLayout.LayoutParams(width, height)); GraphHelper.getInstance().styleLineChart(lineChart); GraphHelper.getInstance().formatChartDataNoThread(posts, lineChart, context); lineChart.measure( View.MeasureSpec.makeMeasureSpec( lineChart.getLayoutParams().width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec( lineChart.getLayoutParams().height, View.MeasureSpec.EXACTLY)); lineChart.layout(0, 0, lineChart.getMeasuredWidth(), lineChart.getMeasuredHeight()); Bitmap b = Bitmap.createBitmap(lineChart.getWidth(), lineChart.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); lineChart.draw(c); return b; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment final View view = inflater.inflate(R.layout.fragment_chart_tab, container, false); btnPrevious = (ImageButton) view.findViewById(R.id.btnPrevious); btnPrevious.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { convertExecutor.execute( new Runnable() { @Override public void run() { if (currentGraph <= 1) { return; } currentGraph--; ChartCollection collection = fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection(); final Map<Double, Double> mapData = collection.getCharData(currentGraph - 1).getData(); // final double[] data = new // double[mapData.values().size()]; // // for (int i = 0; i < mapData.values().size(); i++) { // data[i] = mapData.get(i); // } mainHandler.post( new Runnable() { @Override public void run() { drawGraph(mapData); txtCurrent.setText(String.valueOf(currentGraph)); } }); } }); } }); btnNext = (ImageButton) view.findViewById(R.id.btnNext); btnNext.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { convertExecutor.execute( new Runnable() { @Override public void run() { if (currentGraph >= totalGraphs) { return; } currentGraph++; ChartCollection collection = fromDevice ? fileManager.getCollection() : fileManager.getPcaCollection(); final Map<Double, Double> mapData = collection.getCharData(currentGraph - 1).getData(); // final double[] data = new // double[mapData.values().size()]; // // for (int i = 0; i < mapData.values().size(); i++) { // data[i] = mapData.get(i); // } mainHandler.post( new Runnable() { @Override public void run() { drawGraph(mapData); txtCurrent.setText(String.valueOf(currentGraph)); } }); } }); } }); txtCurrent = (TextView) view.findViewById(R.id.txtCurrentGraph); txtTotal = (TextView) view.findViewById(R.id.txtTotalGraph); chart = (LineChart) view.findViewById(R.id.chart); chart.setNoDataText("Aguardando dados..."); chart.setScaleYEnabled(false); chart.setPinchZoom(true); if (fromDevice) { YAxis leftAxis = chart.getAxisLeft(); leftAxis.setAxisMinValue(0); leftAxis.setAxisMaxValue(100); } YAxis rightAxis = chart.getAxisRight(); rightAxis.setEnabled(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); loadData(true); return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_realtime_chart); // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // setSupportActionBar(toolbar); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_realtime_chart); // mChart = (LineChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); mChart.setDescription("Sleep Cycle live chart"); mChart.setNoDataTextDescription("No sleep data available."); mChart.setTouchEnabled(true); mChart.setDragEnabled(true); mChart.setScaleEnabled(true); mChart.setPinchZoom(true); LineData data = new LineData(); mChart.setData(data); Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); Legend l = mChart.getLegend(); l.setForm(Legend.LegendForm.LINE); l.setTypeface(tf); l.setTextColor(Color.WHITE); XAxis xl = mChart.getXAxis(); xl.setTypeface(tf); xl.setTextColor(Color.WHITE); xl.setDrawGridLines(false); xl.setAvoidFirstLastClipping(true); xl.setSpaceBetweenLabels(5); xl.setEnabled(true); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(tf); leftAxis.setTextColor(Color.WHITE); leftAxis.setAxisMaxValue(100f); leftAxis.setAxisMinValue(0f); leftAxis.setStartAtZero(false); leftAxis.setDrawGridLines(true); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setEnabled(false); // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); // fab.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) // .setAction("Action", null).show(); // } // }); }
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 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_linechart); tvX = (TextView) findViewById(R.id.tvXMax); tvY = (TextView) findViewById(R.id.tvYMax); mSeekBarX = (SeekBar) findViewById(R.id.seekBar1); mSeekBarY = (SeekBar) findViewById(R.id.seekBar2); mSeekBarX.setProgress(45); mSeekBarY.setProgress(100); mSeekBarY.setOnSeekBarChangeListener(this); mSeekBarX.setOnSeekBarChangeListener(this); mChartView = (ChartView) findViewById(R.id.chart1); mChart = (LineChart) mChartView.getChart(); mChart.setOnChartValueSelectedListener(this); // if enabled, the chart will always start at zero on the y-axis mChart.setStartAtZero(true); // enable the drawing of values into the chart mChart.setDrawYValues(true); mChart.setDrawBorder(true); mChart.setBorderPositions(new BorderPosition[] {BorderPosition.BOTTOM}); // no description text mChart.setDescription(""); // invert the y-axis mChart.setInvertYAxisEnabled(true); // 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(true); // set an alternative background color // mChart.setBackgroundColor(Color.GRAY); // create a custom MarkerView (extend MarkerView) and specify the layout // to use for it MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view); // define an offset to change the original position of the marker // (optional) mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight()); // set the marker to the chart mChart.setMarkerView(mv); // enable/disable highlight indicators (the lines that indicate the // highlighted Entry) mChart.setHighlightIndicatorEnabled(false); XLabels xl = mChart.getXLabels(); xl.setAvoidFirstLastClipping(true); // add data setData(25, 50); // // restrain the maximum scale-out factor // mChart.setScaleMinima(3f, 3f); // // // center the view to a specific position inside the chart // mChart.centerViewPort(10, 50); // get the legend (only possible after setting data) Legend l = mChart.getLegend(); // modify the legend ... // l.setPosition(LegendPosition.LEFT_OF_CHART); l.setForm(LegendForm.LINE); // dont forget to refresh the drawing mChartView.invalidate(); }
@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; }