Skip to content

Commit e12e521

Browse files
committed
Minor fixes.
1 parent bb6a556 commit e12e521

File tree

5 files changed

+58
-40
lines changed

5 files changed

+58
-40
lines changed

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

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.github.mikephil.charting.utils.Legend;
2626
import com.github.mikephil.charting.utils.Legend.LegendForm;
2727
import com.github.mikephil.charting.utils.LimitLine.LimitLabelPosition;
28+
import com.github.mikephil.charting.utils.Highlight;
2829
import com.github.mikephil.charting.utils.LimitLine;
2930
import com.github.mikephil.charting.utils.XLabels;
3031
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
@@ -60,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
6061
mChart = (LineChart) findViewById(R.id.chart1);
6162
mChart.setOnChartGestureListener(this);
6263
mChart.setOnChartValueSelectedListener(this);
63-
64+
6465
mChart.setUnit(" $");
6566
mChart.setDrawUnitsInChart(true);
6667

@@ -72,7 +73,7 @@ protected void onCreate(Bundle savedInstanceState) {
7273

7374
mChart.setDrawBorder(true);
7475
mChart.setBorderPositions(new BorderPosition[] {
75-
BorderPosition.BOTTOM
76+
BorderPosition.BOTTOM
7677
});
7778

7879
// no description text
@@ -119,12 +120,12 @@ protected void onCreate(Bundle savedInstanceState) {
119120
// enable/disable highlight indicators (the lines that indicate the
120121
// highlighted Entry)
121122
mChart.setHighlightIndicatorEnabled(false);
122-
123+
123124
// add data
124125
setData(45, 100);
125126

126127
mChart.animateX(2500);
127-
128+
128129
// // restrain the maximum scale-out factor
129130
// mChart.setScaleMinima(3f, 3f);
130131
//
@@ -138,8 +139,8 @@ protected void onCreate(Bundle savedInstanceState) {
138139
// l.setPosition(LegendPosition.LEFT_OF_CHART);
139140
l.setForm(LegendForm.LINE);
140141

141-
// // dont forget to refresh the drawing
142-
// mChart.invalidate();
142+
// // dont forget to refresh the drawing
143+
// mChart.invalidate();
143144
}
144145

145146
@Override
@@ -260,15 +261,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
260261
mChart.disableFiltering();
261262
}
262263
mChart.invalidate();
263-
264-
//
265-
// for(int i = 0; i < 10; i++) {
266-
// mChart.addEntry(new Entry((float) (Math.random() * 100), i+2), 0);
267-
// mChart.invalidate();
268-
// }
269-
//
270-
// Toast.makeText(getApplicationContext(), "valcount: " + mChart.getDataOriginal().getYValCount() + ", valsum: " + mChart.getDataOriginal().getYValueSum(), Toast.LENGTH_SHORT).show();
271-
//
264+
265+
//
266+
// for(int i = 0; i < 10; i++) {
267+
// mChart.addEntry(new Entry((float) (Math.random() * 100),
268+
// i+2), 0);
269+
// mChart.invalidate();
270+
// }
271+
//
272+
// Toast.makeText(getApplicationContext(), "valcount: " +
273+
// mChart.getDataOriginal().getYValCount() + ", valsum: " +
274+
// mChart.getDataOriginal().getYValueSum(),
275+
// Toast.LENGTH_SHORT).show();
276+
//
272277
break;
273278
}
274279
case R.id.actionSave: {
@@ -326,11 +331,11 @@ private void setData(int count, float range) {
326331
// 0.1) / 10);
327332
yVals.add(new Entry(val, i));
328333
}
329-
334+
330335
// create a dataset and give it a type
331336
LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
332-
// set1.setFillAlpha(110);
333-
// set1.setFillColor(Color.RED);
337+
// set1.setFillAlpha(110);
338+
// set1.setFillColor(Color.RED);
334339

335340
// set the line to be drawn like this "- - - - - -"
336341
set1.enableDashedLine(10f, 5f, 0f);
@@ -340,26 +345,27 @@ private void setData(int count, float range) {
340345
set1.setCircleSize(4f);
341346
set1.setFillAlpha(65);
342347
set1.setFillColor(Color.BLACK);
343-
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
348+
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(),
349+
// Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
344350

345351
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
346352
dataSets.add(set1); // add the datasets
347353

348354
// create a data object with the datasets
349355
LineData data = new LineData(xVals, dataSets);
350-
356+
351357
LimitLine ll1 = new LimitLine(130f);
352358
ll1.setLineWidth(4f);
353359
ll1.enableDashedLine(10f, 10f, 0f);
354360
ll1.setDrawValue(true);
355361
ll1.setLabelPosition(LimitLabelPosition.RIGHT);
356-
362+
357363
LimitLine ll2 = new LimitLine(-30f);
358364
ll2.setLineWidth(4f);
359365
ll2.enableDashedLine(10f, 10f, 0f);
360366
ll2.setDrawValue(true);
361367
ll2.setLabelPosition(LimitLabelPosition.RIGHT);
362-
368+
363369
data.addLimitLine(ll1);
364370
data.addLimitLine(ll2);
365371

@@ -374,19 +380,19 @@ public void onChartLongPressed(MotionEvent me) {
374380

375381
@Override
376382
public void onChartDoubleTapped(MotionEvent me) {
377-
Log.i("DoubleTap", "Chart double-tapped.");
383+
Log.i("DoubleTap", "Chart double-tapped.");
378384
}
379385

380386
@Override
381387
public void onChartSingleTapped(MotionEvent me) {
382388
Log.i("SingleTap", "Chart single-tapped.");
383389
}
384-
390+
385391
@Override
386392
public void onValueSelected(Entry e, int dataSetIndex) {
387393
Log.i("Entry selected", e.toString());
388394
}
389-
395+
390396
@Override
391397
public void onNothingSelected() {
392398
Log.i("Nothing selected", "Nothing selected.");

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22
package com.xxmassdeveloper.mpchartexample;
33

44
import android.content.Context;
5-
import android.view.View;
6-
import android.view.View.OnClickListener;
75
import android.widget.TextView;
8-
import android.widget.Toast;
96

107
import com.github.mikephil.charting.data.CandleEntry;
118
import com.github.mikephil.charting.data.Entry;
129
import com.github.mikephil.charting.utils.MarkerView;
1310
import com.github.mikephil.charting.utils.Utils;
1411

15-
public class MyMarkerView extends MarkerView implements OnClickListener {
12+
public class MyMarkerView extends MarkerView {
1613

1714
private TextView tvContent;
1815

1916
public MyMarkerView(Context context, int layoutResource) {
2017
super(context, layoutResource);
2118

2219
tvContent = (TextView) findViewById(R.id.tvContent);
23-
setOnClickListener(this);
2420
}
2521

2622
// callbacks everytime the MarkerView is redrawn, can be used to update the
@@ -38,9 +34,4 @@ public void refreshContent(Entry e, int dataSetIndex) {
3834
tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
3935
}
4036
}
41-
42-
@Override
43-
public void onClick(View v) {
44-
Toast.makeText(getContext(), "Marker clicked!", Toast.LENGTH_SHORT).show();
45-
}
4637
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
import android.graphics.Paint;
1010
import android.graphics.Paint.Align;
1111
import android.graphics.Paint.Style;
12-
import android.graphics.Path;
1312
import android.graphics.PointF;
1413
import android.graphics.Rect;
1514
import android.util.AttributeSet;
1615
import android.util.Log;
1716
import android.view.MotionEvent;
18-
import android.view.ViewParent;
1917

2018
import com.github.mikephil.charting.data.BarDataSet;
2119
import com.github.mikephil.charting.data.BarLineScatterCandleData;

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,10 @@ protected void drawLegend() {
950950
break;
951951
case PIECHART_CENTER:
952952

953-
posX = getWidth() / 2f
954-
- (mLegend.getMaximumEntryLength(mLegendLabelPaint) + mLegend.getXEntrySpace())
953+
posX = getWidth()
954+
/ 2f
955+
- (mLegend.getMaximumEntryLength(mLegendLabelPaint) + mLegend
956+
.getXEntrySpace())
955957
/ 2f;
956958
posY = getHeight() / 2f - mLegend.getFullHeight(mLegendLabelPaint) / 2f;
957959

@@ -1065,6 +1067,26 @@ public void highlightValues(Highlight[] highs) {
10651067
invalidate();
10661068
}
10671069

1070+
/**
1071+
* Highlights the value at the given x-index in the given DataSet. Provide
1072+
* -1 as the x-index to undo all highlighting.
1073+
*
1074+
* @param xIndex
1075+
* @param dataSetIndex
1076+
*/
1077+
public void highlightValue(int xIndex, int dataSetIndex) {
1078+
1079+
if (xIndex < 0 || dataSetIndex < 0 || xIndex >= mOriginalData.getXValCount()
1080+
|| dataSetIndex >= mOriginalData.getDataSetCount()) {
1081+
1082+
highlightValues(null);
1083+
} else {
1084+
highlightValues(new Highlight[] {
1085+
new Highlight(xIndex, dataSetIndex)
1086+
});
1087+
}
1088+
}
1089+
10681090
/**
10691091
* Highlights the value selected by touch gesture. Unlike
10701092
* highlightValues(...), this generates a callback to the
@@ -1713,7 +1735,7 @@ public Legend getLegend() {
17131735
public RectF getContentRect() {
17141736
return mContentRect;
17151737
}
1716-
1738+
17171739
/**
17181740
* disables intercept touchevents
17191741
*/

MPChartLib/src/com/github/mikephil/charting/listener/BarLineChartTouchListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.github.mikephil.charting.data.Entry;
1818
import com.github.mikephil.charting.interfaces.OnChartGestureListener;
1919
import com.github.mikephil.charting.utils.Highlight;
20+
import com.github.mikephil.charting.utils.MarkerView;
2021

2122
/**
2223
* TouchListener for Bar-, Line-, Scatter- and CandleStickChart with handles all

0 commit comments

Comments
 (0)