Android Chart Library Mpandroidchart (a)--to understand his nature, can be handy

Source: Internet
Author: User
Tags radar

Android Chart Library Mpandroidchart (a)--to understand his nature, can be handy

Our project often encountered some statistical charts, such as line charts, lines, etc., in some sports health app especially common, this painting is deadly, I used to be my hand so much, but the end of it is not very deep feeling I, feel, their own white, annoyed, often go to search, Google or , Baidu, are some of the title of the party, what is the simplest, a recruit how how, I saw a half-day Leng even the logic of the writing did not see clear, the main or typesetting is really moving, originally thought that the transfer system after contact, it should be a lot of source and terminal, who know and temporarily transferred to the app department to help, they , can only I on, painting is finished, but for this also endure a few nights, performance and view of the rendering aspect is actually a soft rib, I was thinking, there is no one-way, of course, using some third-party library, these libraries are pretty good, but the style is fixed, of course, We can still through some means to try to achieve the effect we want, all, I choose to learn Mpandroidchart, with him to explain the knowledge of the chart, I hope to let everyone know, how to draw is the simplest, although not cover all the chart, Still I will try my best to write this series so that it won't foggy.

I. Mpandroidchart INTRODUCTION/Integration
    • Github:https://github.com/philjay/mpandroidchart

In accordance with international practice, we must start with the introduction of his documents right, alas, English documents, slowly translated, see his project introduction:

A powerful Android Chart view/graph View Library, supporting Line-bar-pie-radar-bubble-and candlestick charts as we ll as scaling, dragging and animations.

This sentence means a powerful Android chart library, support radar, line chart, and zoom drag animation, from here we can understand that he is a better chart library and support animation, otherwise how to dazzle it, you say yes, we continue to see and get two useful information

    • 1. He supports API8 above
    • 2. He supports the android/ios of two platforms

Look down, is donated, this if you use very good, can give the original author to buy a bottle of beer support ha, we continue to see, he provided an apk to show us, and there is an introduction to the video

    • Mpandroidchart example.apk

Here need to turn over the wall, of course, his source is also some, all not impatient, to here, and then down is how to feedback the description of the bug, we directly ignore, continue to turn, finally see the usage of the words, usage meaning, Let's take a look at how mpandroidchart is integrated, so we're going to build a new Android studio project, and don't ask me why I didn't use eclipse, you know, and of course eclipse is also available because he provides us with jars, Here he offers four ways to add for us, really great, our choice is also more

    • 1.Gradle Dependency

Gradle relies on this for the easiest way, and we're going to use this one, and he needs to add it in your project's Build.gradle first:

allprojects {    repositories {        jcenter()        "https://jitpack.io" }    }}

Then add the Build.gradle in your app

    //MPAndroidChart    ‘com.github.PhilJay:MPAndroidChart:v3.0.0‘

And then sync your project.

    • 2.Maven

This is the configuration of the warehouse, you only need to configure the Pom.xml under your repositories

<repository>    <id>jitpack.io</id>    <url>https://jitpack.io</url></repository>

And then configure it under the pom.xml of your dependencies.

<dependency>    <groupId>com.github.PhilJay</groupId>    <artifactId>MPAndroidChart</artifactId>    <version>v3.0.0</version></dependency>

That's it.

    • 3.Jar

This way is more suitable for eclipse, directly download his jar to add to lib inside.

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

    • 4.Library

Depending on how the library is, just download the mpchartlib in the project and add it to your project and it will be OK.

Further down, is his display, this is no need to say, want to see the students directly to GitHub to see on it, because the blog is expected to write a long, not casually posted pictures, to everyone a final preview of the Portal:

    • Preview: Https://github.com/PhilJay/MPAndroidChart/tree/master/screenshots
Two. Mpandroidchart Project structure/source code download

When you see here, I believe, as long as you are really serious to read, then you are more clear about the Mpandroidchart document, after the document is clear, it is good, we first in Git to execute

git clone https://github.com/PhilJay/MPAndroidChart.git

Cloning his project to local, of course, you directly download zip is also possible, and then you can see

Such a directory, which we really have the meaning of things, just three folders, which four?

    • Mpchartexample: Official case, be sure to see
    • Mpchartlib: The inside is the source code, can also be added directly to the project as a dependency
    • Screenshots: Preview, that is where we just teleport, inside is some of the results after the run, if you want to draw the chart, want to know the Mpandroidchart support, go inside to see and know
Three. Sample Project Setup

Here we have to prepare to use it, we must build a project first, we have to prepare the preparatory work, so that everyone learn or download my sample looks more comfortable, right! Well, we'll create a project--mpandroidchartsample and then follow the above configuration to Gradle dependencies, and then we'll write a few more things like

    • Baseactivity
 Public  class baseactivity extends appcompatactivity {    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);//Show Back buttonGetsupportactionbar (). setdisplayhomeasupenabled (true);//Remove ShadowGetsupportactionbar (). Setelevation (0); }@Override     Public Boolean onoptionsitemselected(MenuItem Item) {//close Current Activity        if(Item.getitemid () = = Android.        R.id.home) {finish (); }return Super. onoptionsitemselected (item); }}

This baseactivity does not have any practical meaning, just shows a return button on the Actionbar, then we write a GridView in the mainactivity layout, and then write in the class:

 Public  class mainactivity extends appcompatactivity  implements  Adapterview. Onitemclicklistener {    //List    PrivateGridView Mgridview;//Data source    PrivateString[] Mstr = {"Line Chart","Line Chart"};//Adapter    PrivateArrayadapter<string> Madapter;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);    Initview (); }//Initialize view    Private void Initview() {Mgridview = (GridView) Findviewbyid (R.id.mgridview); Madapter =NewArrayadapter<string> ( ThisAndroid.        R.layout.simple_list_item_1, MSTR); Mgridview.setadapter (Madapter);//settings ClickMgridview.setonitemclicklistener ( This); }@Override     Public void Onitemclick(adapterview<?> parent, view view,intPositionLongID) {Switch(position) { Case 0://Jump to the corresponding activity here                 Break; }    }}

Here, we can see, this mainactivity actually did not do anything, just a gridview, we achieve what effect, directly in this array to add the line, and then click on the event to jump to the corresponding Activity,ok, which is the front of the cushion, here say, This array we are now default is empty Oh!

Four. Mpchartexample interpretation

We have to be familiar with this framework, then we have to run the example he provided, so as to maximize the understanding of his use, right, that certainly we have to run, here I specifically open a directory for this is because I am in the process of running a lot of problems, all to everyone to say

    • 1. English

      English is nothing, I have translated all over, do not ask me how to translate, Youdao dictionary welcome you, some translation is not OK, probably the meaning of understanding is good

    • 2. Reliance

      Run to import Mpchartexample and Mpchartlib, and mpchartlib settings let the library let mpchartexample add, but I add mpchartlib how all can not import, but manually adjust them for a bit

    • 3.Realm

      When this project more than a database, I did not use, so add a few times after the relevant code has been deleted, so there is no problem;

Finally this project to say, he is eclipse, I demonstrated once

has been integrated and Chinese, I put the demo upload, everyone run under their own look:

    • : http://download.csdn.net/detail/qq_26787115/9684107

I thought I could write a high-quality blog, until I looked at the Mpandroidchart, I think I still sub-series, so to the reader or myself, are very good, we do not enjoy the words, the second chapter began to formally tell the chart, refueling Oh!!

Interested in Dabigatran: 555974449

Android Chart Library Mpandroidchart (a)--to understand his nature, can be handy

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.