您好,如何在 Activity 中包含多个图形? (MPAndroid图表)

Hi, how i can have multiple graphics within a Activity? (MPAndroidChart)

如何在 Activity 中包含多个图形? (MPAndroidChart)

我尝试放置多个图形,但第二个替换了第一个:c

<com.github.mikephil.charting.charts.LineChart
    android:id="@+id/estado_total_grafica_Temperatura"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<com.github.mikephil.charting.charts.LineChart
    android:id="@+id/estado_total_grafica_Humedad"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

这不是图表库的问题。 看来您还没有正确理解 android-layout in xml 的工作原理。

我强烈建议您阅读android developer layout guidelines

至于上面的简单示例,请尝试以下操作:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.github.mikephil.charting.charts.LineChart
    android:id="@+id/estado_total_grafica_Temperatura"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

   <com.github.mikephil.charting.charts.LineChart
    android:id="@+id/estado_total_grafica_Humedad"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

</LinearLayout>

这将使用 weight 属性.

将图表垂直放置在线性布局中