我想在android中使用GraphView繪製線圖。 我可以在y軸上打印標籤,但x軸上的標籤不會顯示,也不會相對於x軸正確繪製點。有人可以請幫助。如何在GraphView中自定義x軸android
請在下面找到
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.GraphActivity">
<TextView
android:id="@+id/linetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bar Graph"
android:textSize="16dp"
android:layout_marginBottom="20dp"/>
<com.jjoe64.graphview.GraphView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:title="Graph Title"
android:id="@+id/graph"
android:layout_below="@+id/linetext"/>
</RelativeLayout>
我的XML代碼的活動代碼如下。
package com.example;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.helper.StaticLabelsFormatter;
public class GraphActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graph_activity_layout);
// Line Graph
GraphView line_graph = (GraphView) findViewById(R.id.graph);
LineGraphSeries<DataPoint> line_series =
new LineGraphSeries<DataPoint>(new DataPoint[] {
new DataPoint(100, -20),
new DataPoint(1000, -15),
new DataPoint(10000, -10),
new DataPoint(12000, -5),
new DataPoint(14000, 0),
new DataPoint(16000, 5),
new DataPoint(18000, 10),
new DataPoint(19000, 15),
new DataPoint(21000, 20)
});
line_graph.addSeries(line_series);
line_series.setDrawDataPoints(true);
line_series.setDataPointsRadius(10);
// set the bound
// set manual X bounds
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(line_graph);
staticLabelsFormatter.setVerticalLabels(new String[] {"-20", "-15", "-10","-5","0","5","10","15","20"});
line_graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
// set manual Y bounds
staticLabelsFormatter.setHorizontalLabels(new String[] {"0","100","1000","10000","24000"});
line_graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);
line_graph.getViewport().setScrollable(true);
}
}
我得到的圖顯示在下面。
我得到y軸的標籤顯示的是-20,-15,-10等,但x軸出故障。我有2個問題
我試過一切,但然後x軸標籤不顯示。 (是的,我已經將x軸標記爲不均勻的(「0」,「100」,「1000」,「0」,「100」,「160」 10000" ,‘24000’),它是在GraphView不允許?因此圖形繪製錯了嗎?
如果是這樣,我可以用一個均勻分佈的情況,但標籤的顯示至少是重要的我
能有人幫。
在此先感謝。