Android realizes user-defined curve chart of price trend

This article refers to the linechart of the open source chart library framework mpadroidchart

Address: https://github.com/PhilJay/MPAndroidChart

1. Demand:

(1) Add RadioButton dynamically, and click to change the following linechart data

(2) Linechart draws a price trend chart, showing only the dots and view at the lowest point, sliding fingers and changes in markview data.

(3) The data returned by the server is not the data of every day, but the data displayed on the x-axis must be the data of every day. I have processed it here. Return the array of points to be displayed in the. The previous time point displays the first point value.

2. Realization effect:

The lowest point display view and small dots are user-defined. By modifying the source code of linechart, let's analyze the code in detail

3. Code analysis

(1) XML for layout

This is mainly to add a radiogroup and a linechart

Next is mainactivity.class

Note: the linechartwidget here is a linechart encapsulated by myself, including linechart initialization, data processing and some operations of gestures

To put it simply, linechart's X and y are user-defined, but I only customize the Y axis here, which hides X. The X axis only displays the starting point and the ending point, so I'm a little speculative here. I set two textviews to display it myself

The point settings of linechart are unified, and all points are set. However, it is required to display only at the lowest point, and draw a view. First initialize the view, and then analyze the data,

Then add RadioButtons dynamically according to the parsed data

Initialize linechart

Set markview

Here is to set the data in linechart

Here is a new place in the source code

Source code modification:

1. Add 2 parameters to the linedataset and copy the newly added method of the ilinedataset

2. Add two methods in the ilinedataset interface

3. Modify the drawvalues (canvas C) method of the source linechartrenderer class. Here is the view to set the lowest point display. Add judgment to this method:

Add judgment in the drawcircles (canvas C) method: the dot at the lowest point can be displayed.

Well, the key parts of all functions have been covered. If you don't understand, you can leave a message and ask questions, or download the source code yourself:

GitHub project address: https://github.com/Songyan992/LineChartStudy

Source download address: linechartstudy_ jb51.rar

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>