private void setData() { RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll(); //RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(result, "yValue"); // stacked entries set.setLabel("Realm RadarDataSet"); set.setDrawFilled(true); set.setColor(ColorTemplate.rgb("#009688")); set.setFillColor(ColorTemplate.rgb("#009688")); set.setFillAlpha(130); set.setLineWidth(2f); ArrayList<IRadarDataSet> dataSets = new ArrayList<IRadarDataSet>(); dataSets.add(set); // add the dataset // create a data object with the dataset list RadarData data = new RadarData(dataSets); styleData(data); // set data mChart.setData(data); mChart.animateY(1400); }
@Override public void setData(float[] data) { ArrayList<RadarEntry> entries1 = new ArrayList<>(); for (float aData : data) { entries1.add(new RadarEntry(aData)); } RadarDataSet set1 = new RadarDataSet(entries1, getString(R.string.app_name)); set1.setColor(Color.rgb(121, 162, 175)); set1.setFillColor(Color.rgb(121, 162, 175)); set1.setDrawFilled(true); set1.setFillAlpha(180); set1.setLineWidth(2f); set1.setDrawHighlightCircleEnabled(true); set1.setDrawHighlightIndicators(false); RadarData radarData = new RadarData(set1); radarData.setValueTextSize(8f); radarData.setDrawValues(false); radarData.setValueTextColor(Color.WHITE); mRadarChart.setData(radarData); mRadarChart.invalidate(); }
private void setData() { RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class); //RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries RealmRadarDataSet<RealmDemoData> set = new RealmRadarDataSet<RealmDemoData>(result, "value", "xIndex"); // stacked entries set.setLabel("Realm RadarDataSet"); set.setDrawFilled(true); set.setColor(ColorTemplate.rgb("#009688")); set.setFillColor(ColorTemplate.rgb("#009688")); set.setFillAlpha(130); set.setLineWidth(2f); ArrayList<IRadarDataSet> dataSets = new ArrayList<IRadarDataSet>(); dataSets.add(set); // add the dataset // create a data object with the dataset list RadarData data = new RadarData(new String[] {"2013", "2014", "2015", "2016", "2017", "2018", "2019"}, dataSets); styleData(data); // set data mChart.setData(data); mChart.animateY(1400); }
@Override public void drawData(Canvas c) { RadarData radarData = mChart.getData(); int mostEntries = radarData.getMaxEntryCountSet().getEntryCount(); IRadarDataSet set; List<IRadarDataSet> dataSets = radarData.getDataSets(); int setCount = dataSets.size(); for(int i = 0 ; i < setCount ; i++){ set = dataSets.get(i); if (set.isVisible()) { drawDataSet(c, set, mostEntries); } } }
public RadarChartCustom(RadarChart graphical, ArrayList<Entry> entries, String entriesLegend, ArrayList<String> labels, String chartDecription) { this.entries = entries; this.chart = graphical; this.dataset = new RadarDataSet(entries, entriesLegend); this.data = new RadarData(labels, this.dataset); this.chart.setData(this.data); this.colors = new ArrayList<>(); this.yAxis = chart.getYAxis(); this.xAxis = chart.getXAxis(); this.legend = chart.getLegend(); this.chart.setSkipWebLineCount(1); if(chartDecription!= null) chart.setDescription(chartDecription); else chart.setDescription(""); setDefaultChart(); setDefaultLegend(); setDefaultAxes(); }
@Override public void drawData(Canvas c) { RadarData radarData = mChart.getData(); int mostEntries = radarData.getMaxEntryCountSet().getEntryCount(); for (IRadarDataSet set : radarData.getDataSets()) { if (set.isVisible()) { drawDataSet(c, set, mostEntries); } } }
@Override public void drawData(Canvas c) { RadarData radarData = mChart.getData(); for (RadarDataSet set : radarData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { float sliceangle = mChart.getSliceAngle(); // calculate the factor that is needed for transforming the value to // pixels float factor = mChart.getFactor(); MPPointF center = mChart.getCenterOffsets(); MPPointF pOut = MPPointF.getInstance(0,0); RadarData radarData = mChart.getData(); for (Highlight high : indices) { IRadarDataSet set = radarData.getDataSetByIndex(high.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; RadarEntry e = set.getEntryForIndex((int) high.getX()); if (!isInBoundsX(e, set)) continue; float y = (e.getY() - mChart.getYChartMin()); Utils.getPosition(center, y * factor * mAnimator.getPhaseY(), sliceangle * high.getX() * mAnimator.getPhaseX() + mChart.getRotationAngle(), pOut); high.setDraw(pOut.x, pOut.y); // draw the lines drawHighlightLines(c, pOut.x, pOut.y, set); if (set.isDrawHighlightCircleEnabled()) { if (!Float.isNaN(pOut.x) && !Float.isNaN(pOut.y)) { int strokeColor = set.getHighlightCircleStrokeColor(); if (strokeColor == ColorTemplate.COLOR_NONE) { strokeColor = set.getColor(0); } if (set.getHighlightCircleStrokeAlpha() < 255) { strokeColor = ColorTemplate.colorWithAlpha(strokeColor, set.getHighlightCircleStrokeAlpha()); } drawHighlightCircle(c, pOut, set.getHighlightCircleInnerRadius(), set.getHighlightCircleOuterRadius(), set.getHighlightCircleFillColor(), strokeColor, set.getHighlightCircleStrokeWidth()); } } } MPPointF.recycleInstance(center); MPPointF.recycleInstance(pOut); }
public void setData() { float mult = 80; float min = 20; int cnt = 5; ArrayList<RadarEntry> entries1 = new ArrayList<RadarEntry>(); ArrayList<RadarEntry> entries2 = new ArrayList<RadarEntry>(); // NOTE: The order of the entries when being added to the entries array determines their position around the center of // the chart. for (int i = 0; i < cnt; i++) { float val1 = (float) (Math.random() * mult) + min; entries1.add(new RadarEntry(val1)); float val2 = (float) (Math.random() * mult) + min; entries2.add(new RadarEntry(val2)); } RadarDataSet set1 = new RadarDataSet(entries1, "Last Week"); set1.setColor(Color.rgb(103, 110, 129)); set1.setFillColor(Color.rgb(103, 110, 129)); set1.setDrawFilled(true); set1.setFillAlpha(180); set1.setLineWidth(2f); set1.setDrawHighlightCircleEnabled(true); set1.setDrawHighlightIndicators(false); RadarDataSet set2 = new RadarDataSet(entries2, "This Week"); set2.setColor(Color.rgb(121, 162, 175)); set2.setFillColor(Color.rgb(121, 162, 175)); set2.setDrawFilled(true); set2.setFillAlpha(180); set2.setLineWidth(2f); set2.setDrawHighlightCircleEnabled(true); set2.setDrawHighlightIndicators(false); ArrayList<IRadarDataSet> sets = new ArrayList<IRadarDataSet>(); sets.add(set1); sets.add(set2); RadarData data = new RadarData(sets); data.setValueTypeface(mTfLight); data.setValueTextSize(8f); data.setDrawValues(false); data.setValueTextColor(Color.WHITE); mChart.setData(data); mChart.invalidate(); }
public void setData() { float mult = 150; int cnt = 9; ArrayList<Entry> yVals1 = new ArrayList<Entry>(); ArrayList<Entry> yVals2 = new ArrayList<Entry>(); // IMPORTANT: In a PieChart, no values (Entry) should have the same // xIndex (even if from different DataSets), since no values can be // drawn above each other. for (int i = 0; i < cnt; i++) { yVals1.add(new Entry((float) (Math.random() * mult) + mult / 2, i)); } for (int i = 0; i < cnt; i++) { yVals2.add(new Entry((float) (Math.random() * mult) + mult / 2, i)); } ArrayList<String> xVals = new ArrayList<String>(); for (int i = 0; i < cnt; i++) xVals.add(mParties[i % mParties.length]); RadarDataSet set1 = new RadarDataSet(yVals1, "Set 1"); set1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]); set1.setFillColor(ColorTemplate.VORDIPLOM_COLORS[0]); set1.setDrawFilled(true); set1.setLineWidth(2f); RadarDataSet set2 = new RadarDataSet(yVals2, "Set 2"); set2.setColor(ColorTemplate.VORDIPLOM_COLORS[4]); set2.setFillColor(ColorTemplate.VORDIPLOM_COLORS[4]); set2.setDrawFilled(true); set2.setLineWidth(2f); ArrayList<IRadarDataSet> sets = new ArrayList<IRadarDataSet>(); sets.add(set1); sets.add(set2); RadarData data = new RadarData(xVals, sets); data.setValueTypeface(tf); data.setValueTextSize(8f); data.setDrawValues(false); mChart.setData(data); mChart.invalidate(); }
@Override ChartData createData(String[] xValues) { return new RadarData(xValues); }
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { float sliceangle = mChart.getSliceAngle(); // calculate the factor that is needed for transforming the value to // pixels float factor = mChart.getFactor(); MPPointF center = mChart.getCenterOffsets(); MPPointF pOut = MPPointF.getInstance(0,0); RadarData radarData = mChart.getData(); for (Highlight high : indices) { IRadarDataSet set = radarData.getDataSetByIndex(high.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; RadarEntry e = set.getEntryForIndex((int) high.getX()); if (!isInBoundsX(e, set)) continue; float y = (e.getY() - mChart.getYChartMin()); Utils.getPosition(center, y * factor * mAnimator.getPhaseY(), sliceangle * high.getX() * mAnimator.getPhaseX() + mChart.getRotationAngle(), pOut); high.setDraw(pOut.x, pOut.y); // draw the lines drawHighlightLines(c, pOut.x, pOut.y, set); if (set.isDrawHighlightCircleEnabled()) { if (!Float.isNaN(pOut.x) && !Float.isNaN(pOut.y)) { int strokeColor = set.getHighlightCircleStrokeColor(); if (strokeColor == ColorTemplate.COLOR_NONE) { strokeColor = set.getColor(0); } if (set.getHighlightCircleStrokeAlpha() < 255) { strokeColor = ColorTemplate.getColorWithAlphaComponent(strokeColor, set.getHighlightCircleStrokeAlpha()); } drawHighlightCircle(c, pOut, set.getHighlightCircleInnerRadius(), set.getHighlightCircleOuterRadius(), set.getHighlightCircleFillColor(), strokeColor, set.getHighlightCircleStrokeWidth()); } } } MPPointF.recycleInstance(center); MPPointF.recycleInstance(pOut); }