Skip to content

Commit f39d891

Browse files
committed
Work on radarchart
1 parent 4b058a5 commit f39d891

6 files changed

Lines changed: 57 additions & 30 deletions

File tree

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
4-
android:layout_height="match_parent" >
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
8+
<TextView
9+
android:layout_width="match_parent"
10+
android:layout_height="0dp"
11+
android:layout_weight="0.5"
12+
android:gravity="center"
13+
android:textAppearance="?android:attr/textAppearanceLarge"
14+
android:text="YOUR PREFERENCES"
15+
android:id="@+id/textView"/>
516

617
<com.github.mikephil.charting.charts.RadarChart
718
android:id="@+id/chart1"
819
android:layout_width="match_parent"
9-
android:layout_height="match_parent" />
20+
android:layout_height="0dp"
21+
android:layout_weight="2" />
1022

11-
</RelativeLayout>
23+
</LinearLayout>

MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivitry.java

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

22
package com.xxmassdeveloper.mpchartexample;
33

4+
import android.graphics.Color;
45
import android.graphics.Typeface;
56
import android.os.Bundle;
67
import android.view.Menu;
78
import android.view.MenuItem;
89
import android.view.WindowManager;
10+
import android.widget.TextView;
911
import android.widget.Toast;
1012

1113
import com.github.mikephil.charting.animation.Easing;
@@ -37,16 +39,23 @@ protected void onCreate(Bundle savedInstanceState) {
3739
super.onCreate(savedInstanceState);
3840
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
3941
WindowManager.LayoutParams.FLAG_FULLSCREEN);
40-
setContentView(R.layout.activity_radarchart);
41-
42-
mChart = (RadarChart) findViewById(R.id.chart1);
42+
setContentView(R.layout.activity_radarchart_noseekbar);
4343

4444
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
4545

46+
TextView tv = (TextView) findViewById(R.id.textView);
47+
tv.setTypeface(tf);
48+
tv.setTextColor(Color.WHITE);
49+
tv.setBackgroundColor(Color.rgb(60, 65, 82));
50+
51+
mChart = (RadarChart) findViewById(R.id.chart1);
52+
mChart.setBackgroundColor(Color.rgb(60, 65, 82));
53+
4654
mChart.setDescription("");
4755

48-
mChart.setWebLineWidth(1.5f);
49-
mChart.setWebLineWidthInner(0.75f);
56+
mChart.setWebLineWidth(1f);
57+
mChart.setWebColor(Color.LTGRAY);
58+
mChart.setWebLineWidthInner(1f);
5059
mChart.setWebAlpha(100);
5160

5261
// create a custom MarkerView (extend MarkerView) and specify the layout
@@ -66,29 +75,36 @@ protected void onCreate(Bundle savedInstanceState) {
6675
XAxis xAxis = mChart.getXAxis();
6776
xAxis.setTypeface(tf);
6877
xAxis.setTextSize(9f);
78+
xAxis.setYOffset(0f);
79+
xAxis.setXOffset(0f);
6980
xAxis.setValueFormatter(new AxisValueFormatter() {
81+
82+
private String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};
7083
@Override
7184
public String getFormattedValue(float value, AxisBase axis) {
72-
return mMonths[(int) value % mMonths.length];
85+
return mActivities[(int) value % mActivities.length];
7386
}
7487

7588
@Override
7689
public int getDecimalDigits() {
7790
return 0;
7891
}
7992
});
93+
xAxis.setTextColor(Color.WHITE);
8094

8195
YAxis yAxis = mChart.getYAxis();
8296
yAxis.setTypeface(tf);
8397
yAxis.setLabelCount(5, false);
8498
yAxis.setTextSize(9f);
8599
yAxis.setAxisMinValue(0f);
100+
yAxis.setDrawLabels(false);
86101

87102
Legend l = mChart.getLegend();
88-
l.setPosition(LegendPosition.RIGHT_OF_CHART);
103+
l.setPosition(LegendPosition.ABOVE_CHART_CENTER);
89104
l.setTypeface(tf);
90105
l.setXEntrySpace(7f);
91106
l.setYEntrySpace(5f);
107+
l.setTextColor(Color.WHITE);
92108
}
93109

94110
@Override
@@ -190,15 +206,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
190206
return true;
191207
}
192208

193-
private String[] mParties = new String[]{
194-
"Party A", "Party B", "Party C", "Party D", "Party E", "Party F", "Party G", "Party H",
195-
"Party I"
196-
};
197-
198209
public void setData() {
199210

200-
float mult = 150;
201-
int cnt = 9;
211+
float mult = 80;
212+
float min = 20;
213+
int cnt = 5;
202214

203215
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
204216
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
@@ -207,25 +219,27 @@ public void setData() {
207219
// xIndex (even if from different DataSets), since no values can be
208220
// drawn above each other.
209221
for (int i = 0; i < cnt; i++) {
210-
float val = (float) (Math.random() * mult) + mult / 2;
222+
float val = (float) (Math.random() * mult) + min;
211223
yVals1.add(new Entry(i, val));
212224
}
213225

214226
for (int i = 0; i < cnt; i++) {
215-
float val = (float) (Math.random() * mult) + mult / 2;
227+
float val = (float) (Math.random() * mult) + min;
216228
yVals2.add(new Entry(i, val));
217229
}
218230

219-
RadarDataSet set1 = new RadarDataSet(yVals1, "Set 1");
220-
set1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
221-
set1.setFillColor(ColorTemplate.VORDIPLOM_COLORS[0]);
231+
RadarDataSet set1 = new RadarDataSet(yVals1, "Last Week");
232+
set1.setColor(Color.rgb(103, 110, 129));
233+
set1.setFillColor(Color.rgb(103, 110, 129));
222234
set1.setDrawFilled(true);
235+
set1.setFillAlpha(180);
223236
set1.setLineWidth(2f);
224237

225-
RadarDataSet set2 = new RadarDataSet(yVals2, "Set 2");
226-
set2.setColor(ColorTemplate.VORDIPLOM_COLORS[4]);
227-
set2.setFillColor(ColorTemplate.VORDIPLOM_COLORS[4]);
238+
RadarDataSet set2 = new RadarDataSet(yVals2, "This Week");
239+
set2.setColor(Color.rgb(121, 162, 175));
240+
set2.setFillColor(Color.rgb(121, 162, 175));
228241
set2.setDrawFilled(true);
242+
set2.setFillAlpha(180);
229243
set2.setLineWidth(2f);
230244

231245
ArrayList<IRadarDataSet> sets = new ArrayList<IRadarDataSet>();
@@ -236,6 +250,7 @@ public void setData() {
236250
data.setValueTypeface(tf);
237251
data.setValueTextSize(8f);
238252
data.setDrawValues(false);
253+
data.setValueTextColor(Color.WHITE);
239254

240255
mChart.setData(data);
241256
mChart.invalidate();

MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ protected void onCreate(Bundle savedInstanceState) {
6262
mChart.setOnChartValueSelectedListener(this);
6363

6464
mChart.setDrawGridBackground(false);
65-
6665
mChart.setTouchEnabled(true);
66+
mChart.setMaxHighlightDistance(50f);
6767

6868
// enable scaling and dragging
6969
mChart.setDragEnabled(true);

MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieRadarChartBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void calculateOffsets() {
217217
XAxis x = this.getXAxis();
218218

219219
if (x.isEnabled() && x.isDrawLabelsEnabled()) {
220-
minOffset = Math.max(minOffset, x.mLabelRotatedWidth * 2f);
220+
minOffset = Math.max(minOffset, x.mLabelRotatedWidth);
221221
}
222222
}
223223

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/RadarChartRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ protected void drawWeb(Canvas c) {
228228
mWebPaint.setColor(mChart.getWebColorInner());
229229
mWebPaint.setAlpha(mChart.getWebAlpha());
230230

231-
int labelCount = mChart.getYAxis().mEntries.length;
231+
int labelCount = mChart.getYAxis().mEntryCount;
232232

233233
for (int j = 0; j < labelCount; j++) {
234234

MPChartLib/src/main/java/com/github/mikephil/charting/renderer/XAxisRendererRadarChart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void renderAxisLabels(Canvas c) {
4747
float angle = (sliceangle * i + mChart.getRotationAngle()) % 360f;
4848

4949
PointF p = Utils.getPosition(center, mChart.getYRange() * factor
50-
+ mXAxis.mLabelRotatedWidth, angle);
50+
+ mXAxis.mLabelRotatedWidth / 2f, angle);
5151

5252
drawLabel(c, label, p.x, p.y - mXAxis.mLabelRotatedHeight / 2.f,
5353
drawLabelAnchor, labelRotationAngleDegrees);

0 commit comments

Comments
 (0)