简体   繁体   English

如何使用Android中的MPAndroid图表库将x和y轴叠加在折线图顶部?

[英]How to overlay the x and y axis on top of line chart using MPAndroid chart library in Android?

I have read the whole documentation of MPAndroid Chart library but haven't found anything to do so. 我已经阅读了MPAndroid Chart库的整个文档,但没有发现任何事情。 I actually want my chart to extend to full width of screen so that the x and y axis comes to top of the chart. 我实际上希望我的图表扩展到屏幕的整个宽度,以便x和y轴到达图表的顶部。 I have attached an image to show how should it look exactly. 我附上了一张图片,以展示它应该如何精确。

该图表应该看起来像屏幕的上半部分

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">

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



    <FrameLayout
        android:id="@+id/workout_frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="17"
        android:background="@color/dashboard_item1"
        android:foreground="?attr/selectableItemBackground"
        android:padding="15dp">


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="36dp"
                android:layout_height="match_parent"
                android:src="@drawable/nav_workout_icon" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_marginLeft="10dp">

                <TextView
                    android:id="@+id/workout_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/workout_title"
                    android:textColor="@color/text_primary"
                    android:textSize="20sp"/>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/workout_calories_consumed"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/workout_calories_consumed_sample"
                        android:textColor="@color/text_primary"
                        android:textSize="26sp"
                        android:textStyle="bold"/>

                    <TextView
                        android:id="@+id/calorie_unit_workout_left"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/calorie_unit"
                        android:textColor="@color/text_secondary"
                        android:textSize="20sp"
                        android:layout_marginLeft="7dp"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_gravity="right"
            android:gravity="center">

            <TextView
                android:id="@+id/workout_calories_total"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/workout_calories_total_sample"
                android:textColor="@color/accent"
                android:textSize="22sp"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/workout_unit_calorie_right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/calorie_unit"
                android:textColor="@color/accent"
                android:textSize="18sp"/>
        </LinearLayout>
    </FrameLayout>

    <FrameLayout
        android:id="@+id/diet_frame"
        android:foreground="?attr/selectableItemBackground"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="17"
        android:background="@color/dashboard_item2"
        android:padding="15dp">


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="36dp"
                android:layout_height="match_parent"
                android:src="@drawable/nav_diet_icon" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_marginLeft="10dp">

                <TextView
                    android:id="@+id/diet_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/diet_title"
                    android:textColor="@color/text_primary"
                    android:textSize="20sp"/>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/diet_calories_consumed"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/diet_calories_consumed_sample"
                        android:textColor="@color/text_primary"
                        android:textSize="26sp"
                        android:textStyle="bold"/>

                    <TextView
                        android:id="@+id/calorie_unit_diet_left"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/calorie_unit"
                        android:textColor="@color/text_secondary"
                        android:textSize="20sp"
                        android:layout_marginLeft="7dp"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_gravity="right"
            android:gravity="center">

            <TextView
                android:id="@+id/diet_calories_total"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/diet_calories_total_sample"
                android:textColor="@color/accent"
                android:textSize="22sp"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/diet_unit_calorie_right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/calorie_unit"
                android:textColor="@color/accent"
                android:textSize="18sp"/>
        </LinearLayout>

    </FrameLayout>

    <TextView
        android:id="@+id/sync_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:textColor="@android:color/black"
        android:visibility="gone" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:visibility="gone">

        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textColor="@android:color/black"
            android:visibility="gone" />
    </ScrollView>
</LinearLayout>

Edited: This is my layout xml code. 编辑:这是我的布局xml代码。

You can setPosition(YAxisLabelPosition pos): Sets the position where the axis-labels should be drawn. 你可以setPosition(YAxisLabelPosition pos):设置应该绘制轴标签的位置。 Either INSIDE_CHART or OUTSIDE_CHART. INSIDE_CHART或OUTSIDE_CHART。

Also you can set Bottom or Top position. 您也可以设置Bottom或Top位置。

 XAxis xAxis = chart.getXAxis();
 xAxis.setPosition(XAxisPosition.TOP);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM