【问题标题】:Android MPChart resets scrollingXAndroid MPChart 重置滚动X
【发布时间】:2020-09-02 12:19:53
【问题描述】:

所以我目前使用 PhilJay (https://github.com/PhilJay/MPAndroidChart) 的 MPChart 库,但我在 x 轴上滚动时遇到了一些问题,因为当我尝试滚动两次时它会重置...我不知道如何用文字准确地描述它,所以这是我的问题的视频:

https://youtu.be/h04RItDrE34

如您所见,我无法滚动很远,因为当我尝试第二次滚动时,图表会立即从我开始第一次滚动的地方开始,而不是结束的地方...

这是我修改 LineChart 的代码(不应该滚动):

LineChart graphView;

public ECGView(LineChart graphView){
    this.graphView = graphView;

    setup(graphView);
}

public LineChart getGraphView(){
    return graphView;
}

public void addFloatArrayToSeries(float[] floats, int color){
    ArrayList<Entry> entries = new ArrayList<>();

    int i = 0;
    for(float val : floats){
        entries.add(new Entry(i, val));
        i++;
    }
    LineDataSet lineDataSet = new LineDataSet(entries, "ECG");
    lineDataSet.setColor(color);

    ArrayList<ILineDataSet> lineDataSetif = new ArrayList<>();
    lineDataSetif.add(lineDataSet);
    LineData lineData = new LineData(lineDataSetif);

    graphView.clear();
    graphView.setData(lineData);

}

public void setup(LineChart graphView){
    graphView.setBackgroundColor(Color.rgb(45,45,45));
    graphView.setScaleYEnabled(false);
}

以及来自 Android 的 xml 布局代码:

<androidx.cardview.widget.CardView
    android:id="@+id/ecg_box"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_margin="10dp"
    android:shape="ring"
    app:cardCornerRadius="20dp"
    app:cardElevation="20dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.13">

    <com.github.mikephil.charting.charts.LineChart
        android:id="@+id/ecg_viewer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="5dp"/>

</androidx.cardview.widget.CardView>

谁能帮帮我?

【问题讨论】:

    标签: java android charts scroll mpandroidchart


    【解决方案1】:

    我自己想通了,但是我的图表所在的 Cardview 是问题所在......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多