Skip to content

Commit c22b47c

Browse files
committed
Worked on RadarChart. Fixed known issues.
1 parent 289b71a commit c22b47c

19 files changed

Lines changed: 509 additions & 350 deletions

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected void onCreate(Bundle savedInstanceState) {
6363

6464
mChart.setDrawHoleEnabled(true);
6565

66-
66+
mChart.setRotationAngle(0);
6767

6868
// draws the corresponding description value into the slice
6969
mChart.setDrawXValues(true);

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.github.mikephil.charting.utils.ColorTemplate;
1616
import com.github.mikephil.charting.utils.Legend;
1717
import com.github.mikephil.charting.utils.Legend.LegendPosition;
18+
import com.github.mikephil.charting.utils.YLabels;
19+
import com.github.mikephil.charting.utils.YLabels.YLabelPosition;
1820
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
1921

2022
import java.util.ArrayList;
@@ -37,16 +39,21 @@ protected void onCreate(Bundle savedInstanceState) {
3739
mChart.setValueTypeface(tf);
3840

3941
mChart.setDescription("");
40-
42+
4143
mChart.setWebLineWidth(2f);
4244
mChart.setWebLineWidthInner(0.75f);
4345

4446
setData();
4547

46-
mChart.animateXY(1500, 1500);
48+
YLabels yl = mChart.getYLabels();
49+
yl.setTypeface(tf);
50+
yl.setLabelCount(5);
51+
52+
// mChart.animateXY(1500, 1500);
4753

4854
Legend l = mChart.getLegend();
4955
l.setPosition(LegendPosition.RIGHT_OF_CHART);
56+
l.setTypeface(tf);
5057
l.setXEntrySpace(7f);
5158
l.setYEntrySpace(5f);
5259
}
@@ -56,8 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {
5663
};
5764

5865
public void setData() {
59-
60-
float mult = 100;
66+
67+
float mult = 150;
6168

6269
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
6370
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
@@ -68,7 +75,7 @@ public void setData() {
6875
for (int i = 0; i < 6; i++) {
6976
yVals1.add(new Entry((float) (Math.random() * mult) + mult / 2, i));
7077
}
71-
78+
7279
for (int i = 0; i < 6; i++) {
7380
yVals2.add(new Entry((float) (Math.random() * mult) + mult / 2, i));
7481
}
@@ -80,14 +87,14 @@ public void setData() {
8087

8188
RadarDataSet set1 = new RadarDataSet(yVals1, "Set 1");
8289
set1.setColor(getResources().getColor(R.color.vordiplom_1));
83-
// set1.setDrawFilled(true);
90+
// set1.setDrawFilled(true);
8491
set1.setLineWidth(2f);
85-
92+
8693
RadarDataSet set2 = new RadarDataSet(yVals2, "Set 2");
8794
set2.setColor(getResources().getColor(R.color.vordiplom_5));
88-
// set2.setDrawFilled(true);
95+
// set2.setDrawFilled(true);
8996
set2.setLineWidth(2f);
90-
97+
9198
ArrayList<RadarDataSet> sets = new ArrayList<RadarDataSet>();
9299
sets.add(set1);
93100
sets.add(set2);

‎MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import android.view.MotionEvent;
1616
import android.view.ViewParent;
1717

18-
import com.github.mikephil.charting.data.BarLineScatterCandleData;
18+
import com.github.mikephil.charting.data.BarLineScatterCandleRadarData;
1919
import com.github.mikephil.charting.data.ChartData;
2020
import com.github.mikephil.charting.data.Entry;
2121
import com.github.mikephil.charting.data.filter.Approximator;
@@ -100,9 +100,6 @@ public abstract class BarLineChartBase extends Chart {
100100
/** paint for the y-label values */
101101
protected Paint mYLabelPaint;
102102

103-
/** paint used for highlighting values */
104-
protected Paint mHighlightPaint;
105-
106103
/** paint used for the limit lines */
107104
protected Paint mLimitLinePaint;
108105

@@ -195,11 +192,6 @@ protected void init() {
195192
mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240)); // light
196193
// grey
197194

198-
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
199-
mHighlightPaint.setStyle(Paint.Style.STROKE);
200-
mHighlightPaint.setStrokeWidth(2f);
201-
mHighlightPaint.setColor(Color.rgb(255, 187, 115));
202-
203195
mLimitLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
204196
mLimitLinePaint.setStyle(Paint.Style.STROKE);
205197
}
@@ -608,7 +600,7 @@ private void prepareYLabels() {
608600
// 90
609601
interval = Math.floor(10 * intervalMagnitude);
610602
}
611-
603+
612604
double first = Math.ceil(yMin / interval) * interval;
613605
double last = Utils.nextUp(Math.floor(yMax / interval) * interval);
614606

@@ -906,7 +898,7 @@ protected void drawVerticalGrid() {
906898
*/
907899
private void drawLimitLines() {
908900

909-
ArrayList<LimitLine> limitLines = ((BarLineScatterCandleData) mOriginalData)
901+
ArrayList<LimitLine> limitLines = ((BarLineScatterCandleRadarData) mOriginalData)
910902
.getLimitLines();
911903

912904
if (limitLines == null)

‎MPChartLib/src/com/github/mikephil/charting/charts/Chart.java‎

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ public abstract class Chart extends View implements AnimatorUpdateListener {
119119
/**
120120
* paint object used for darwing the bitmap to the screen
121121
*/
122-
protected Paint mDrawPaint;
122+
protected Paint mDrawPaint;
123+
124+
/** paint used for highlighting values */
125+
protected Paint mHighlightPaint;
123126

124127
/**
125128
* paint object used for drawing the description text in the bottom right
@@ -188,7 +191,7 @@ public abstract class Chart extends View implements AnimatorUpdateListener {
188191
protected boolean mDrawLegend = true;
189192

190193
/** this rectangle defines the area in which graph values can be drawn */
191-
protected Rect mContentRect = new Rect();
194+
protected RectF mContentRect = new RectF();
192195

193196
/** the legend object containing all data associated with the legend */
194197
protected Legend mLegend;
@@ -262,7 +265,12 @@ protected void init() {
262265
mLegendFormPaint.setStrokeWidth(3f);
263266

264267
mLegendLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
265-
mLegendLabelPaint.setTextSize(Utils.convertDpToPixel(9f));
268+
mLegendLabelPaint.setTextSize(Utils.convertDpToPixel(9f));
269+
270+
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
271+
mHighlightPaint.setStyle(Paint.Style.STROKE);
272+
mHighlightPaint.setStrokeWidth(2f);
273+
mHighlightPaint.setColor(Color.rgb(255, 187, 115));
266274
}
267275

268276
// public void initWithDummyData() {
@@ -1028,60 +1036,64 @@ protected void drawMarkers() {
10281036
for (int i = 0; i < mIndicesToHightlight.length; i++) {
10291037

10301038
int xIndex = mIndicesToHightlight[i].getXIndex();
1039+
int dataSetIndex = mIndicesToHightlight[i].getDataSetIndex();
1040+
1041+
if (xIndex <= mDeltaX && xIndex <= mDeltaX * mPhaseX) {
1042+
1043+
Entry e = getEntryByDataSetIndex(xIndex, dataSetIndex);
1044+
1045+
// make sure entry not null
1046+
if (e == null)
1047+
continue;
1048+
1049+
float[] pos = getMarkerPosition(e, dataSetIndex);
10311050

1032-
if (xIndex <= mDeltaX && xIndex <= mDeltaX * mPhaseX)
1033-
drawMarkerView(xIndex, mIndicesToHightlight[i].getDataSetIndex());
1051+
// callbacks to update the content
1052+
mMarkerView.refreshContent(e, dataSetIndex);
1053+
1054+
mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
1055+
}
10341056
}
10351057
}
10361058

10371059
/**
1038-
* Draws the view that is displayed when a value is highlighted.
1060+
* Returns the actual position in pixels of the MarkerView for the given
1061+
* Entry in the given DataSet.
10391062
*
1040-
* @param xIndex the selected x-index
1041-
* @param dataSetIndex the index of the selected DataSet
1063+
* @param xIndex
1064+
* @param dataSetIndex
1065+
* @return
10421066
*/
1043-
private void drawMarkerView(int xIndex, int dataSetIndex) {
1067+
private float[] getMarkerPosition(Entry e, int dataSetIndex) {
10441068

1045-
Entry e = getEntryByDataSetIndex(xIndex, dataSetIndex);
1046-
1047-
// make sure the entry is not null
1048-
if (e == null) {
1049-
return;
1050-
}
1051-
1052-
float xPos = (float) xIndex;
1069+
float xPos = (float) e.getXIndex();
10531070

10541071
// make sure the marker is in the center of the bars in BarChart and
10551072
// CandleStickChart
10561073
if (this instanceof CandleStickChart)
10571074
xPos += 0.5f;
1058-
1059-
else if(this instanceof BarChart) {
1060-
1075+
1076+
else if (this instanceof BarChart) {
1077+
10611078
BarData bd = (BarData) mCurrentData;
10621079
float space = bd.getGroupSpace();
1063-
float j = mCurrentData.getDataSetByIndex(dataSetIndex).getEntryPosition(e);
1064-
1065-
float x = (j * (mCurrentData.getDataSetCount() - 1)) + dataSetIndex + space * j + space / 2f + 0.5f;
1066-
1067-
xPos += x;
1080+
float j = mCurrentData.getDataSetByIndex(dataSetIndex)
1081+
.getEntryPosition(e);
1082+
1083+
float x = (j * (mCurrentData.getDataSetCount() - 1)) + dataSetIndex + space * j + space
1084+
/ 2f + 0.5f;
1085+
1086+
xPos += x;
10681087
}
10691088

10701089
// position of the marker depends on selected value index and value
10711090
float[] pts = new float[] {
10721091
xPos, e.getVal() * mPhaseY
10731092
};
1093+
10741094
transformPointArray(pts);
10751095

1076-
float posX = pts[0];
1077-
float posY = pts[1];
1078-
1079-
// callbacks to update the content
1080-
mMarkerView.refreshContent(e, dataSetIndex);
1081-
1082-
// call the draw method of the markerview that will translate to the
1083-
// given position and draw the view
1084-
mMarkerView.draw(mDrawCanvas, posX, posY);
1096+
return pts;
10851097
}
10861098

10871099
/**
@@ -1365,7 +1377,7 @@ public int getValueCount() {
13651377
* @return
13661378
*/
13671379
public PointF getCenter() {
1368-
return new PointF(getWidth() / 2, getHeight() / 2);
1380+
return new PointF(getWidth() / 2f, getHeight() / 2f);
13691381
}
13701382

13711383
/**
@@ -1559,7 +1571,7 @@ public Legend getLegend() {
15591571
*
15601572
* @return
15611573
*/
1562-
public Rect getContentRect() {
1574+
public RectF getContentRect() {
15631575
return mContentRect;
15641576
}
15651577

0 commit comments

Comments
 (0)