Hellocharts-android-android charting the use of open source libraries (i)

Source: Internet
Author: User
Tags polyline

Recent projects need to use the chart, the technology is limited, it is difficult to achieve their own, so after comparison, finally decided to use hellocharts this open source Library, Portal: Https://github.com/lecho/hellocharts-android, First, because the introduction of convenience, the second is the code is relatively clear, easy to add to the project. Another important reason, this library can support the Line table, the column table, the pie table and the bubble table, and the effect is very good, put a few pictures of people to feel:


1.gif
2.png
3.png
4.png
5.png


How, the effect is not very flashy ah, below we see how to use it.
PS: This article operates based on Android Studio

Import Hellocharts

There are three ways to use hellocharts in our projects.

    1. Thanks to Android Studio, which allows us to use some open source libraries very conveniently, if your development tool is it, then the introduction of the project is very simple, just need to add the following code in the dependencies closure of the build file under your app, and then sync:
      dependencies{compile ‘com.github.lecho:hellocharts-library:[email protected]‘ }
    2. Of course, we can also download the latest Jar package to import and use, click Https://github.com/lecho/hellocharts-android/releases, you will see the author released the latest Jar package. After you download the jar package, put it in the Libs folder under the app directory and sync the project.
    3. Although the first two methods are more convenient, but can not modify the source of the library, sometimes we need to make some changes on the basis of the open source Library, this time we can add module to the way to import. The import process is also very simple.
      First, we can download the code locally on the Project home page. There are two ways of doing this:

Download the project. png


If GIT is configured locally, we can just run git clone [email protected]:lecho/hellocharts-android.git to clone the project locally, otherwise click Download zip.
After the project is downloaded locally, in your own project, select File-new-import Module, then select Hellocharts-library OK to complete the import.


Source directory. png

Use of basic line tables

After a few steps, our project has now become hellocharts, let's take a look at the most basic chart-how to use the Line table.
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" />

In Hellocharts, each chart has its own data type, in the Line table, the final set to the chart shows the Linechartdata, we can simply think, this data is bound to include the line, the line of points, as well as the axis, below we are shown in code.

    1. Declare a polyline
      Line line = new Line(values).setColor(Color.BLUE);//声明线并设置颜色line.setCubic(false);//设置是平滑的还是直的lines = new ArrayList<Line>();lines.add(line);
    2. Initialize points on a polyline
      values = new ArrayList<PointValue>();//折线上的点values.add(new PointValue(0, 2));values.add(new PointValue(1, 4));values.add(new PointValue(2, 3));values.add(new PointValue(3, 4));
    3. Set the related properties and data for a Line table
      mChartView.setInteractive(true);//设置图表是可以交互的(拖拽,缩放等效果的前提)mChartView.setZoomType(ZoomType.HORIZONTAL_AND_VERTICAL);//设置缩放方向LineChartData data = new LineChartData();Axis axisX = new Axis();//x轴Axis axisY = new Axis();//y轴data.setAxisXBottom(axisX);data.setAxisYLeft(axisY);data.setLines(lines);mChartView.setLineChartData(data);//给图表设置数据
      With these simple settings (and finally the demo address), we can see the basic line chart effect:

Demo effect. png

Here, we have successfully used hellocharts this powerful chart library to show a basic line chart, there are a lot of cool usage waiting for us to explore. Finally put on the demo address: Https://github.com/SolveBugs/HelloChartDemo

Hellocharts-android-android charting the use of open source libraries (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.