Skip to content

Commit b0f5ec1

Browse files
committed
Example cleanup and improvements
1 parent e5af569 commit b0f5ec1

17 files changed

Lines changed: 61 additions & 124 deletions

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ protected void onCreate(Bundle savedInstanceState) {
7373
mChart.animateY(2500);
7474

7575
mChart.getLegend().setEnabled(false);
76-
77-
// Legend l = mChart.getLegend();
78-
// l.setPosition(LegendPosition.BELOW_CHART_CENTER);
79-
// l.setFormSize(8f);
80-
// l.setFormToTextSpace(4f);
81-
// l.setXEntrySpace(6f);
82-
83-
// mChart.setDrawLegend(false);
8476
}
8577

8678
@Override

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.annotation.SuppressLint;
55
import android.graphics.PointF;
66
import android.graphics.RectF;
7-
import android.graphics.Typeface;
87
import android.os.Bundle;
98
import android.util.Log;
109
import android.view.Menu;
@@ -47,8 +46,6 @@ public class BarChartActivity extends DemoBase implements OnSeekBarChangeListene
4746
private SeekBar mSeekBarX, mSeekBarY;
4847
private TextView tvX, tvY;
4948

50-
private Typeface mTf;
51-
5249
@Override
5350
protected void onCreate(Bundle savedInstanceState) {
5451
super.onCreate(savedInstanceState);
@@ -80,11 +77,9 @@ protected void onCreate(Bundle savedInstanceState) {
8077
mChart.setDrawGridBackground(false);
8178
// mChart.setDrawYLabels(false);
8279

83-
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
84-
8580
XAxis xAxis = mChart.getXAxis();
8681
xAxis.setPosition(XAxisPosition.BOTTOM);
87-
xAxis.setTypeface(mTf);
82+
xAxis.setTypeface(mTfLight);
8883
xAxis.setDrawGridLines(false);
8984
xAxis.setGranularity(1f); // only intervals of 1 day
9085
xAxis.setLabelCount(7);
@@ -93,7 +88,7 @@ protected void onCreate(Bundle savedInstanceState) {
9388
AxisValueFormatter custom = new MyAxisValueFormatter();
9489

9590
YAxis leftAxis = mChart.getAxisLeft();
96-
leftAxis.setTypeface(mTf);
91+
leftAxis.setTypeface(mTfLight);
9792
leftAxis.setLabelCount(8, false);
9893
leftAxis.setValueFormatter(custom);
9994
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
@@ -102,7 +97,7 @@ protected void onCreate(Bundle savedInstanceState) {
10297

10398
YAxis rightAxis = mChart.getAxisRight();
10499
rightAxis.setDrawGridLines(false);
105-
rightAxis.setTypeface(mTf);
100+
rightAxis.setTypeface(mTfLight);
106101
rightAxis.setLabelCount(8, false);
107102
rightAxis.setValueFormatter(custom);
108103
rightAxis.setSpaceTop(15f);
@@ -254,7 +249,7 @@ private void setData(int count, float range) {
254249

255250
BarData data = new BarData(dataSets);
256251
data.setValueTextSize(10f);
257-
data.setValueTypeface(mTf);
252+
data.setValueTypeface(mTfLight);
258253
data.setBarWidth(0.9f);
259254

260255
mChart.setData(data);

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package com.xxmassdeveloper.mpchartexample;
33

44
import android.graphics.Color;
5-
import android.graphics.Typeface;
65
import android.os.Bundle;
76
import android.util.Log;
87
import android.view.Menu;
@@ -38,8 +37,6 @@ public class BarChartActivityMultiDataset extends DemoBase implements OnSeekBarC
3837
private BarChart mChart;
3938
private SeekBar mSeekBarX, mSeekBarY;
4039
private TextView tvX, tvY;
41-
42-
private Typeface tf;
4340

4441
@Override
4542
protected void onCreate(Bundle savedInstanceState) {
@@ -74,27 +71,21 @@ protected void onCreate(Bundle savedInstanceState) {
7471
// to use for it
7572
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
7673

77-
// define an offset to change the original position of the marker
78-
// (optional)
79-
// mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
80-
8174
// set the marker to the chart
8275
mChart.setMarkerView(mv);
8376

8477
mSeekBarX.setProgress(10);
8578
mSeekBarY.setProgress(100);
8679

87-
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
88-
8980
Legend l = mChart.getLegend();
9081
l.setPosition(LegendPosition.RIGHT_OF_CHART_INSIDE);
91-
l.setTypeface(tf);
82+
l.setTypeface(mTfLight);
9283
l.setYOffset(0f);
9384
l.setYEntrySpace(0f);
9485
l.setTextSize(8f);
9586

9687
XAxis xl = mChart.getXAxis();
97-
xl.setTypeface(tf);
88+
xl.setTypeface(mTfLight);
9889
xl.setGranularity(1f);
9990
xl.setCenterAxisLabels(true);
10091
xl.setValueFormatter(new AxisValueFormatter() {
@@ -110,7 +101,7 @@ public int getDecimalDigits() {
110101
});
111102

112103
YAxis leftAxis = mChart.getAxisLeft();
113-
leftAxis.setTypeface(tf);
104+
leftAxis.setTypeface(mTfLight);
114105
leftAxis.setValueFormatter(new LargeValueFormatter());
115106
leftAxis.setDrawGridLines(false);
116107
leftAxis.setSpaceTop(30f);
@@ -253,7 +244,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
253244
data.setValueFormatter(new LargeValueFormatter());
254245

255246
// add space between the dataset groups in percent of bar-width
256-
data.setValueTypeface(tf);
247+
data.setValueTypeface(mTfLight);
257248

258249
mChart.setData(data);
259250
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package com.xxmassdeveloper.mpchartexample;
33

44
import android.graphics.Color;
5-
import android.graphics.Typeface;
65
import android.os.Bundle;
76
import android.view.Menu;
87
import android.view.MenuItem;
@@ -34,8 +33,6 @@ public class BarChartActivitySinus extends DemoBase implements OnSeekBarChangeLi
3433
private SeekBar mSeekBarX;
3534
private TextView tvX;
3635

37-
private Typeface mTf;
38-
3936
private List<BarEntry> mSinusData;
4037

4138
@Override
@@ -73,13 +70,11 @@ protected void onCreate(Bundle savedInstanceState) {
7370
mChart.setDrawGridBackground(false);
7471
// mChart.setDrawYLabels(false);
7572

76-
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
77-
7873
XAxis xAxis = mChart.getXAxis();
7974
xAxis.setEnabled(false);
8075

8176
YAxis leftAxis = mChart.getAxisLeft();
82-
leftAxis.setTypeface(mTf);
77+
leftAxis.setTypeface(mTfLight);
8378
leftAxis.setLabelCount(6, false);
8479
leftAxis.setAxisMinValue(-2.5f);
8580
leftAxis.setAxisMaxValue(2.5f);
@@ -88,7 +83,7 @@ protected void onCreate(Bundle savedInstanceState) {
8883

8984
YAxis rightAxis = mChart.getAxisRight();
9085
rightAxis.setDrawGridLines(false);
91-
rightAxis.setTypeface(mTf);
86+
rightAxis.setTypeface(mTfLight);
9287
rightAxis.setLabelCount(6, false);
9388
rightAxis.setAxisMinValue(-2.5f);
9489
rightAxis.setAxisMaxValue(2.5f);
@@ -222,7 +217,7 @@ private void setData(int count) {
222217

223218
BarData data = new BarData(set);
224219
data.setValueTextSize(10f);
225-
data.setValueTypeface(mTf);
220+
data.setValueTypeface(mTfLight);
226221
data.setDrawValues(false);
227222
data.setBarWidth(0.8f);
228223

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package com.xxmassdeveloper.mpchartexample;
33

44
import android.graphics.Color;
5-
import android.graphics.Typeface;
65
import android.os.Bundle;
76
import android.util.Log;
87
import android.view.Menu;
@@ -36,8 +35,6 @@ public class BubbleChartActivity extends DemoBase implements OnSeekBarChangeList
3635
private BubbleChart mChart;
3736
private SeekBar mSeekBarX, mSeekBarY;
3837
private TextView tvX, tvY;
39-
40-
private Typeface tf;
4138

4239
@Override
4340
protected void onCreate(Bundle savedInstanceState) {
@@ -58,8 +55,6 @@ protected void onCreate(Bundle savedInstanceState) {
5855
mChart = (BubbleChart) findViewById(R.id.chart1);
5956
mChart.setDescription("");
6057

61-
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
62-
6358
mChart.setOnChartValueSelectedListener(this);
6459

6560
mChart.setDrawGridBackground(false);
@@ -78,10 +73,10 @@ protected void onCreate(Bundle savedInstanceState) {
7873

7974
Legend l = mChart.getLegend();
8075
l.setPosition(LegendPosition.RIGHT_OF_CHART);
81-
l.setTypeface(tf);
76+
l.setTypeface(mTfLight);
8277

8378
YAxis yl = mChart.getAxisLeft();
84-
yl.setTypeface(tf);
79+
yl.setTypeface(mTfLight);
8580
yl.setSpaceTop(30f);
8681
yl.setSpaceBottom(30f);
8782
yl.setDrawZeroLine(false);
@@ -90,7 +85,7 @@ protected void onCreate(Bundle savedInstanceState) {
9085

9186
XAxis xl = mChart.getXAxis();
9287
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
93-
xl.setTypeface(tf);
88+
xl.setTypeface(mTfLight);
9489
}
9590

9691
@Override
@@ -205,7 +200,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
205200
// create a data object with the datasets
206201
BubbleData data = new BubbleData(dataSets);
207202
data.setDrawValues(false);
208-
data.setValueTypeface(tf);
203+
data.setValueTypeface(mTfLight);
209204
data.setValueTextSize(8f);
210205
data.setValueTextColor(Color.WHITE);
211206
data.setHighlightCircleWidth(1.5f);

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ protected void onCreate(Bundle savedInstanceState) {
8080
mSeekBarY.setProgress(100);
8181

8282
mChart.getLegend().setEnabled(false);
83-
84-
// Legend l = mChart.getLegend();
85-
// l.setPosition(LegendPosition.BELOW_CHART_CENTER);
86-
// l.setFormSize(8f);
87-
// l.setFormToTextSpace(4f);
88-
// l.setXEntrySpace(6f);
89-
90-
// mChart.setDrawLegend(false);
9183
}
9284

9385
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public int getDecimalDigits() {
9595
data.setData(generateBubbleData());
9696
data.setData(generateScatterData());
9797
data.setData(generateCandleData());
98+
data.setValueTypeface(mTfLight);
9899

99100
xAxis.setAxisMaxValue(data.getXMax() + 0.25f);
100101

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package com.xxmassdeveloper.mpchartexample;
33

44
import android.graphics.Color;
5-
import android.graphics.Typeface;
65
import android.os.Bundle;
76
import android.view.Menu;
87
import android.view.MenuItem;
@@ -32,8 +31,6 @@ public class CubicLineChartActivity extends DemoBase implements OnSeekBarChangeL
3231
private LineChart mChart;
3332
private SeekBar mSeekBarX, mSeekBarY;
3433
private TextView tvX, tvY;
35-
36-
private Typeface tf;
3734

3835
@Override
3936
protected void onCreate(Bundle savedInstanceState) {
@@ -73,13 +70,11 @@ protected void onCreate(Bundle savedInstanceState) {
7370

7471
mChart.setDrawGridBackground(false);
7572

76-
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
77-
7873
XAxis x = mChart.getXAxis();
7974
x.setEnabled(false);
8075

8176
YAxis y = mChart.getAxisLeft();
82-
y.setTypeface(tf);
77+
y.setTypeface(mTfLight);
8378
y.setLabelCount(6, false);
8479
y.setTextColor(Color.WHITE);
8580
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
@@ -307,7 +302,7 @@ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProv
307302

308303
// create a data object with the datasets
309304
LineData data = new LineData(set1);
310-
data.setValueTypeface(tf);
305+
data.setValueTypeface(mTfLight);
311306
data.setValueTextSize(9f);
312307
data.setDrawValues(false);
313308

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.annotation.SuppressLint;
55
import android.graphics.PointF;
66
import android.graphics.RectF;
7-
import android.graphics.Typeface;
87
import android.os.Bundle;
98
import android.util.Log;
109
import android.view.Menu;
@@ -40,8 +39,6 @@ public class HorizontalBarChartActivity extends DemoBase implements OnSeekBarCha
4039
private SeekBar mSeekBarX, mSeekBarY;
4140
private TextView tvX, tvY;
4241

43-
private Typeface tf;
44-
4542
@Override
4643
protected void onCreate(Bundle savedInstanceState) {
4744
super.onCreate(savedInstanceState);
@@ -77,25 +74,23 @@ protected void onCreate(Bundle savedInstanceState) {
7774

7875
mChart.setDrawGridBackground(false);
7976

80-
tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
81-
8277
XAxis xl = mChart.getXAxis();
8378
xl.setPosition(XAxisPosition.BOTTOM);
84-
xl.setTypeface(tf);
79+
xl.setTypeface(mTfLight);
8580
xl.setDrawAxisLine(true);
8681
xl.setDrawGridLines(false);
8782
xl.setGridLineWidth(0.3f);
8883
xl.setGranularity(10f);
8984

9085
YAxis yl = mChart.getAxisLeft();
91-
yl.setTypeface(tf);
86+
yl.setTypeface(mTfLight);
9287
yl.setDrawAxisLine(true);
9388
yl.setDrawGridLines(true);
9489
yl.setAxisMinValue(0f); // this replaces setStartAtZero(true)
9590
// yl.setInverted(true);
9691

9792
YAxis yr = mChart.getAxisRight();
98-
yr.setTypeface(tf);
93+
yr.setTypeface(mTfLight);
9994
yr.setDrawAxisLine(true);
10095
yr.setDrawGridLines(false);
10196
yr.setAxisMinValue(0f); // this replaces setStartAtZero(true)
@@ -247,7 +242,7 @@ private void setData(int count, float range) {
247242

248243
BarData data = new BarData(dataSets);
249244
data.setValueTextSize(10f);
250-
data.setValueTypeface(tf);
245+
data.setValueTypeface(mTfLight);
251246
data.setBarWidth(barWidth);
252247
mChart.setData(data);
253248
}

0 commit comments

Comments
 (0)