Today, to record what LineChart (line chart) is simple to use!
Note: I use the version MPAndroidChart-v3.0.3 (Should have some way to update a different version, can leave a message in the comments area, do everything I can to help you solve!)
This article will talk about how to draw a simple line graph (there is a little bit small landscaping)
MPAndroidChart detail using --LineChart line graph (b) (depth landscaping)
First on renderings:
Since the code is relatively simple, so nothing can be particularly speaking, some comments in the code of
xml file
Just add such a control on it (is not very simple ~)
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="300dp">
</com.github.mikephil.charting.charts.LineChart>
Java file
public class LineChartActivity extends AppCompatActivity {
private LineChart line;
List<Entry>list=new ArrayList<>(); //实例化一个 List 用来保存你的数据
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_line_chart);
line = (LineChart) findViewById(R.id.line);
list.add(new Entry(0,7)); //其中两个数字对应的分别是 X轴 Y轴
list.add(new Entry(1,10));
list.add(new Entry(2,12));
list.add(new Entry(3,6));
list.add(new Entry(4,3));
//list是你这条线的数据 "语文" 是你对这条线的描述(也就是图例上的文字)
LineDataSet lineDataSet=new LineDataSet(list,"语文");
LineData lineData=new LineData(lineDataSet);
line.setData(lineData);
//简单美化
// X轴所在位置 默认为上面
line.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
//隐藏右边的Y轴
line.getAxisRight().setEnabled(false);
}
}
This way a simple line graph to draw good!