From 13c693ee06f4d4b8572ce59546c1896921bbe067 Mon Sep 17 00:00:00 2001 From: Emma Guy Date: Wed, 13 Aug 2014 10:13:52 +0100 Subject: [PATCH] added ability to customise 'no data available' text and added an optional description --- .../mikephil/charting/charts/Chart.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/MPChartLib/src/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/com/github/mikephil/charting/charts/Chart.java index 5458fe106..051b77e11 100644 --- a/MPChartLib/src/com/github/mikephil/charting/charts/Chart.java +++ b/MPChartLib/src/com/github/mikephil/charting/charts/Chart.java @@ -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; @@ -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) { @@ -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 @@ -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; }