Recent projects need to use charts, technology co., LTD., their hard to implement, so after comparison, finally decided to use the hellocharts this open source libraries, portal: https://github.com/lecho/hellocharts-android, because the introduction of a convenient, Second, the code is also relatively clear, easy to add to the project. Another important reason is that the library can support broken line tables, columnar tables, pie tables and bubble tables, and the implementation is very good. Here are a few images for you to feel:

Import hellocharts

There are three ways to use HelloCharts in our project.

  1. Add the following code to the Dependencies closure of the build file in your app and sync it:
dependencies{
 compile 'com. Making. Lecho: hellocharts - library: 1.5.8 @ aar' 
}
Copy the code
  1. Of course, we also can download the latest jars used to import, click https://github.com/lecho/hellocharts-android/releases, will see the author’s latest jars. After downloading the JAR package, put it in the LIBS folder in the app directory, and then synchronize the project.
  2. Although the first two methods are more convenient, but can not modify the source of the library, sometimes we need to make some changes based on the open source library, in this case we can add module to import. The import process is also very simple. First, we can download the code locally from the project home page. There are two ways:

Basic line table use

After the above steps, our project has successfully become HelloCharts. Now let’s take a look at how the most basic chart-line table is used. First, add the line table control to the XML file:

<lecho.lib.hellocharts.view.LineChartView    
android:id="@+id/chart"    
android:layout_width="match_parent"
android:layout_height="match_parent" />
Copy the code

In HelloCharts, each chart has its own data type. In the line chart, LineChartData is finally set to be displayed on the chart. We can simply think that this data must contain lines, points on lines and coordinate axes.

  1. Declare a fold line
Line line = new Line(values).setColor(Color.BLUE); // Declare the line and set the color line.setcubic (false); // Set lines to smooth or straight = new ArrayList<Line>(); lines.add(line);Copy the code
  1. Initialize a point on a polyline
values = new ArrayList<PointValue>(); Value. add(new PointValue(0, 2)); values.add(new PointValue(1, 4)); values.add(new PointValue(2, 3)); values.add(new PointValue(3, 4));Copy the code
  1. Set the properties and data of the line table
mChartView.setInteractive(true); SetZoomType (zoomType.horizontal_and_vertical); McHartview.setzoomtype (zoomType.horizontal_and_vertical); LineChartData data = new LineChartData(); Axis axisX = new Axis(); // axisY = new Axis(); / / y data. SetAxisXBottom (axisX); data.setAxisYLeft(axisY); data.setLines(lines); mChartView.setLineChartData(data); // Set the data for the chartCopy the code

After a few simple steps (with the demo address at the end), we can now see the basic line chart:

So far, we have successfully used the helloCharts powerful chart library to show a basic line chart, and there are many cool uses waiting to be discovered. Finally put the demo address: https://github.com/SolveBugs/HelloChartDemo