PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.52k stars 9.01k forks source link

moveViewToX() not working when updating the chart #4443

Open hyyu opened 5 years ago

hyyu commented 5 years ago

Hi,

I'm trying to add data on my chart (a barchart) 20 elements by 20 from the most recent the oldest ones (right to left). As real-time isn't supported by MPAndroidChart, I'm clearing the chart of its bars.

However, I need to move the view to the last item that has been loaded (so the 20th, even if there are some bars after that)

The call to get 20 more elements is called when the user reaches the end of the chart (I'm using the OnChartGestureListener with its method onChartGestureEnd for that).

The problem is that when the 20 elements are added (at the start), the chart keeps its view to the start (check on Screenshots) instead of being moved to the 20th element.

Before loading 20 more elements

After loading the 20 elements

The view should have placed the "12 feb" bar on the right with the moveViewToX() function instead of staying on the start of the chart.

I also have a problem about the bars taking a uncommon width after changing the date type with the switcher on the top of the screen.

Width before switching

Width after switching

I don't have anything in my code modifying the bar widths.

If you want any part of code from me, I will give it in answer.

AlephC commented 5 years ago

May I see your Gradle.Build? Both App and Project.

On Mon, Mar 4, 2019, 14:39 hyyu notifications@github.com wrote:

Hi,

I'm trying to add data on my chart (a barchart) 20 elements by 20 from the most recent the oldest ones (right to left). As real-time isn't supported by MPAndroidChart, I'm clearing the chart of its bars.

However, I need to move the view to the last item that has been loaded (so the 20th, even if there are some bars after that)

The call to get 20 more elements is called when the user reaches the end of the chart (I'm using the OnChartGestureListener with its method onChartGestureEnd for that).

The problem is that when the 20 elements are added (at the start), the chart keeps its view to the start (check on Screenshots) instead of being moved to the 20th element.

Before loading 20 more elements

https://user-images.githubusercontent.com/13220072/53750902-4cc7c100-3eab-11e9-877f-e456548acc8a.png

After loading the 20 elements

https://user-images.githubusercontent.com/13220072/53751084-c3fd5500-3eab-11e9-8977-aee3579f693c.png

The view should have placed the "12 feb" bar on the right with the moveViewToX() function instead of staying on the start of the chart.

I also have a problem about the bars taking a uncommon width after changing the date type with the switcher on the top of the screen.

Width before switching

https://user-images.githubusercontent.com/13220072/53751355-61f11f80-3eac-11e9-803a-b741225c163d.png

Width after switching

https://user-images.githubusercontent.com/13220072/53751390-746b5900-3eac-11e9-9f78-3414393df453.png

I don't have anything in my code modifying the bar widths.

If you want any part of code from me, I will give it in answer.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PhilJay/MPAndroidChart/issues/4443, or mute the thread https://github.com/notifications/unsubscribe-auth/Aefcy6zranrkry_6eac1EnjfLwh891Kfks5vTVpLgaJpZM4bc2-g .

hyyu commented 5 years ago

Hi, here are the gradle files. For the lib, I cloned it and used it a lib for the project. I have a version dating from a week ago.

project:

buildscript {
    ext.kotlin_version = '1.3.21'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

app:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

ext.minimumSdkVersion = 23
ext.versionMajor = 2
ext.versionMinor = 0
ext.versionPatch = 0

ext.lifecycleVersion = '2.1.0-alpha02'
ext.room_version = '1.1.1'

repositories {
    maven { url "https://jitpack.io" }
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.enovap"
        minSdkVersion project.ext.minimumSdkVersion
        targetSdkVersion 28
        versionCode generateVersionCode()
        versionName generateVersionName()
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    /* Kotlin */
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    /* AndroidX dependencies */
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
    implementation 'androidx.core:core-ktx:1.1.0-alpha04'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"

    /* Joda Time */
    implementation 'net.danlew:android.joda:2.9.9.4'

    /* Permissions */
    implementation 'com.karumi:dexter:4.1.0'

    /* CircularProgressButton */
    implementation 'br.com.simplepass:loading-button-android:1.14.0'

    /* RippleBackground */
    implementation 'com.skyfishjy.ripplebackground:library:1.0.1'

    /* Carousel View */
    implementation 'com.synnapps:carouselview:0.1.5'

    /* Retrofit */
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation('com.squareup.retrofit2:converter-simplexml:2.4.0')
    implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'

    /* Multidex */
    implementation 'androidx.multidex:multidex:2.0.1'

    /* Firebase */
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.firebase:firebase-messaging:17.4.0'

    /* RxBle */
    implementation "com.polidea.rxandroidble2:rxandroidble:1.7.1"

    /* MPAndroidChart */
    implementation project(':mpchartlib')

    /* Enovap BLE */
    implementation project(':enovapble')

    /* Room */
    implementation "android.arch.persistence.room:runtime:$room_version"
    kapt "android.arch.persistence.room:compiler:$room_version"

    /* Google play services */
    apply plugin: 'com.google.gms.google-services'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

}

private Integer generateVersionCode() {
    return ext.minimumSdkVersion * 10000000 + ext.versionMajor * 10000 + ext.versionMinor * 100 + ext.versionPatch
}

private String generateVersionName() {
    return "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
}
AlephC commented 5 years ago

Hi. Why don't you set 'mavenCentral()' or 'apply plugin: 'maven' in your gradle files?

On Tue, Mar 5, 2019, 06:03 hyyu notifications@github.com wrote:

Hi, here are the gradle files

project:

buildscript { ext.kotlin_version = '1.3.21' repositories { google() jcenter()

}
dependencies {
    classpath 'com.google.gms:google-services:4.2.0'
    classpath 'com.android.tools.build:gradle:3.3.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

}

allprojects { repositories { google() jcenter() } }

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

app:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

ext.minimumSdkVersion = 23 ext.versionMajor = 2 ext.versionMinor = 0 ext.versionPatch = 0

ext.lifecycleVersion = '2.1.0-alpha02' ext.room_version = '1.1.1'

repositories { maven { url "https://jitpack.io" } }

android { compileSdkVersion 28 defaultConfig { applicationId "com.enovap" minSdkVersion project.ext.minimumSdkVersion targetSdkVersion 28 versionCode generateVersionCode() versionName generateVersionName() testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])

/* Kotlin */
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

/* AndroidX dependencies */
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.core:core-ktx:1.1.0-alpha04'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"

/* Joda Time */
implementation 'net.danlew:android.joda:2.9.9.4'

/* Permissions */
implementation 'com.karumi:dexter:4.1.0'

/* CircularProgressButton */
implementation 'br.com.simplepass:loading-button-android:1.14.0'

/* RippleBackground */
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'

/* Carousel View */
implementation 'com.synnapps:carouselview:0.1.5'

/* Retrofit */
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation('com.squareup.retrofit2:converter-simplexml:2.4.0')
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'

/* Multidex */
implementation 'androidx.multidex:multidex:2.0.1'

/* Firebase */
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-messaging:17.4.0'

/* RxBle */
implementation "com.polidea.rxandroidble2:rxandroidble:1.7.1"

/* MPAndroidChart */
implementation project(':mpchartlib')

/* Enovap BLE */
implementation project(':enovapble')

/* Room */
implementation "android.arch.persistence.room:runtime:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"

/* Google play services */
apply plugin: 'com.google.gms.google-services'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

}

private Integer generateVersionCode() { return ext.minimumSdkVersion 10000000 + ext.versionMajor 10000 + ext.versionMinor * 100 + ext.versionPatch }

private String generateVersionName() { return "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}" }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PhilJay/MPAndroidChart/issues/4443#issuecomment-469597591, or mute the thread https://github.com/notifications/unsubscribe-auth/Aefcy4FgFIr9N7OfghebdndYnydPRRYgks5vTjL1gaJpZM4bc2-g .