6

I'm a new MPAndroidChart user.

The examples I have found on-line and the Wiki here all give the setDescription() prototype as:

setDescription(String desc)`

However, mChart.setDescription(""); does not compile for me and AndroidStudio->Go To Declaration tells me the declaration for setDescription defined in Chart.java is :

   public void setDescription(Description desc) {
        this.mDescription = desc;
    }

And the Description constructor in Description.java does not take a String.

How do I set the description (or at least turn it off)? Am I pointing to the wrong libraries?

Here is my app's gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And, the module gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.android.nbmc_hbmc"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'pub.devrel:easypermissions:0.2.1'
    testCompile 'junit:junit:4.12'
}

And this is my chart code. It compiles and shows the chart but it has the Description Label "Description Label" that I can't change or turn off.

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import java.util.ArrayList;
import java.util.List;

import static com.example.android.nbmc_hbmc.R.id.chart;

public class NbmcEcgGraphActivity extends Activity {


    private RelativeLayout mainLayout;
    private LineChart mChart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ecggraph);
        mainLayout = (RelativeLayout) findViewById(R.id.activity_ecggraph);

        // Create new line chart
        LineChart mChart = (LineChart) findViewById(chart);

        mChart.setDescription(new Description());
        mChart.setNoDataText("No Data Yet");

1 Answer 1

22

It looks like the wiki is out of date!

The correct syntax in MPAndroidChart 3.0.1 is

mChart.getDescription().setText("Description of my chart");

Reference: javadoc

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks -- your solution works. (I'd +1 if I could).
Cheers, this helped me.Don't forget to close the quote on that string.
This doesn't work for mePieChart pieChart = findViewById(R.id.piechart); pieChart.getDescription().setText("Description of my chart"); it gives the error cant resolve method getDescription()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.