Skip to content

Commit

Permalink
Merge pull request #29 from emmaguy/customise_no_data_text
Browse files Browse the repository at this point in the history
Added ability to customise 'no data available' text
  • Loading branch information
PhilJay committed Aug 15, 2014
2 parents 878c3e6 + 13c693e commit 4f151cd
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion MPChartLib/src/com/github/mikephil/charting/charts/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.graphics.Typeface;
import android.os.Environment;
import android.provider.MediaStore.Images;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
Expand Down Expand Up @@ -187,6 +188,8 @@ public abstract class Chart extends View {

/** listener that is called when a value on the chart is selected */
protected OnChartValueSelectedListener mSelectionListener;
private String mNoDataText = "No chart data available.";
private String mNoDataTextDescription;

/** default constructor for initialization in code */
public Chart(Context context) {
Expand Down Expand Up @@ -310,6 +313,23 @@ public void setData(ChartData data) {
Log.i(LOG_TAG, "Data is set.");
}

/**
* Informs the user that there is no data available with which to draw the chart
* @param text
*/
public void setNoDataText(String text) {
mNoDataText = text;
}

/**
* Sets descriptive text to explain to the user why there is no chart available
* Defaults to empty if not set
* @param text
*/
public void setNoDataTextDescription(String text) {
mNoDataTextDescription = text;
}

/**
* Sets primitive data for the chart. Internally, this is converted into a
* ChartData object with one DataSet (type 0). If you have more specific
Expand Down Expand Up @@ -380,7 +400,12 @@ protected void onDraw(Canvas canvas) {
if (mDataNotSet) { // check if there is data

// if no data, inform the user
canvas.drawText("No chart data available.", getWidth() / 2, getHeight() / 2, mInfoPaint);
canvas.drawText(mNoDataText, getWidth() / 2, getHeight() / 2, mInfoPaint);

if(!TextUtils.isEmpty(mNoDataTextDescription)) {
float textOffset = -mInfoPaint.ascent() + mInfoPaint.descent();
canvas.drawText(mNoDataTextDescription, getWidth() / 2, (getHeight() / 2) + textOffset, mInfoPaint);
}
return;
}

Expand Down

0 comments on commit 4f151cd

Please sign in to comment.