当前位置:  开发笔记 > 编程语言 > 正文

如何在MPAndroidChart中设置描述?

如何解决《如何在MPAndroidChart中设置描述?》经验,为你挑选了1个好方法。

我是一个新的MPAndroidChart用户.

我已经在网上和维基中发现的例子在这里都给予了setDescription()的原型为:

setDescription(String desc)`

但是,mChart.setDescription("");不能为我编译和AndroidStudio-> Go To Declaration告诉我Chart.java中定义的setDescription声明是:

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

Description.java中的Description构造函数不接受String.

如何设置描述(或至少将其关闭)?我指的是错误的图书馆吗?

这是我的应用程序的gradle文件:

// 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
}

并且,模块gradle文件:

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'
}

这是我的图表代码.它编译并显示图表,但它有描述标签"描述标签",我无法更改或关闭.

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");

David Rawson.. 12

看起来维基已经过时了!

MPAndroidChart3.0.1中的正确语法是

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

参考:javadoc



1> David Rawson..:

看起来维基已经过时了!

MPAndroidChart3.0.1中的正确语法是

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

参考:javadoc

推荐阅读
夏晶阳--艺术
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有