Skip to content

Commit f516b45

Browse files
committed
Fixed issue concerning multiple lines not being drawn with one entry (issue PhilJay#127).
1 parent 1c984be commit f516b45

6 files changed

Lines changed: 33 additions & 24 deletions

File tree

-125 Bytes
Binary file not shown.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
200200
@Override
201201
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
202202

203-
tvX.setText("" + (mSeekBarX.getProgress() + 1));
203+
tvX.setText("" + (mSeekBarX.getProgress()));
204204
tvY.setText("" + (mSeekBarY.getProgress()));
205205

206206
ArrayList<String> xVals = new ArrayList<String>();
207207
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
208208
xVals.add((i) + "");
209209
}
210-
210+
211211
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
212212

213213
for (int z = 0; z < 3; z++) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ protected void calculateOffsets() {
327327
// calculate the maximum y-label width (including eventual offsets)
328328
float ylabelwidth = Utils.calcTextWidth(mYLabelPaint,
329329
label + mUnit + (mYChartMin < 0 ? "----" : "+++")); // offsets
330-
331-
Log.i(LOG_TAG, "OFFSETS, labelwidth: " + ylabelwidth + ", label: " + label);
332-
330+
333331
if (mDrawYLabels) {
334332

335333
// offsets for y-labels

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ public void setData(T data) {
347347
"Cannot set data for chart. Provided data object is null.");
348348
return;
349349
}
350+
351+
// Log.i(LOG_TAG, "xvalcount: " + data.getXValCount());
352+
// Log.i(LOG_TAG, "entrycount: " + data.getYValCount());
350353

351354
// LET THE CHART KNOW THERE IS DATA
352355
mDataNotSet = false;
@@ -630,8 +633,11 @@ protected float[] generateTransformedValuesLineScatter(ArrayList<? extends Entry
630633
float[] valuePoints = new float[entries.size() * 2];
631634

632635
for (int j = 0; j < valuePoints.length; j += 2) {
633-
valuePoints[j] = entries.get(j / 2).getXIndex();
634-
valuePoints[j + 1] = entries.get(j / 2).getVal() * mPhaseY;
636+
637+
Entry e = entries.get(j / 2);
638+
639+
valuePoints[j] = e.getXIndex();
640+
valuePoints[j + 1] = e.getVal() * mPhaseY;
635641
}
636642

637643
transformPointArray(valuePoints);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ protected void calcMinMax(boolean fixedValues) {
5757
super.calcMinMax(fixedValues);
5858

5959
// if there is only one value in the chart
60-
if (mOriginalData.getYValCount() == 1) {
60+
if (mOriginalData.getYValCount() == 1
61+
|| mOriginalData.getYValCount() <= mOriginalData.getDataSetCount()) {
6162
mDeltaX = 1;
6263
}
6364
}
@@ -366,14 +367,15 @@ protected void drawAdditional() {
366367

367368
// make sure the circles don't do shitty things outside
368369
// bounds
369-
if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1])
370+
if (isOffContentLeft(positions[j]) ||
371+
isOffContentTop(positions[j + 1])
370372
|| isOffContentBottom(positions[j + 1]))
371373
continue;
372374

373375
mDrawCanvas.drawCircle(positions[j], positions[j + 1], dataSet.getCircleSize(),
374376
mRenderPaint);
375377
mDrawCanvas.drawCircle(positions[j], positions[j + 1],
376-
dataSet.getCircleSize() / 2,
378+
dataSet.getCircleSize() / 2f,
377379
mCirclePaintInner);
378380
}
379381
} // else do nothing

MPChartLib/src/com/github/mikephil/charting/data/ChartData.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,20 @@ public int getYValCount() {
294294
return mYValCount;
295295
}
296296

297-
/**
298-
* Checks if the ChartData object contains valid data
299-
*
300-
* @return
301-
*/
302-
public boolean isValid() {
303-
if (mXVals == null || mXVals.size() < 1)
304-
return false;
305-
306-
if (mDataSets == null || mDataSets.size() < 1)
307-
return false;
308-
309-
return true;
310-
}
297+
// /**
298+
// * Checks if the ChartData object contains valid data
299+
// *
300+
// * @return
301+
// */
302+
// public boolean isValid() {
303+
// if (mXVals == null || mXVals.size() < 1)
304+
// return false;
305+
//
306+
// if (mDataSets == null || mDataSets.size() < 1)
307+
// return false;
308+
//
309+
// return true;
310+
// }
311311

312312
/**
313313
* returns the x-values the chart represents
@@ -613,6 +613,9 @@ public T getDataSetForEntry(Entry e) {
613613
*/
614614
public int[] getColors() {
615615

616+
if (mDataSets == null)
617+
return null;
618+
616619
int clrcnt = 0;
617620

618621
for (int i = 0; i < mDataSets.size(); i++) {

0 commit comments

Comments
 (0)