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); }
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); }
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); }