Android Trend chart creation and use

Source: Internet
Author: User

Prior to the project needs to have a requirement is to draw a trend chart according to the weekly weather temperature, this figure is not based on XY coordinates, is a simple trend map, Baidu after reading some blog, basically have some ideas, the following is the whole trend map:

The bottom point line chart is the effect to be done.

The following is a sample code for the trend diagram:

Package Com.example.testxyjar;import Utils. Xyviewdrawbitmap;import Utils. Xyviewdrawline;import Utils. Xyviewdrawpointer;import Utils. Xyviewdrawtext;import view. Xyview;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.color;import Android.graphics.drawable.bitmapdrawable;import Android.graphics.drawable.drawable;import Android.os.Bundle; Import Android.view.menu;import Bean. Xyviewbitmapbean;import Bean. Xyviewlinebean;import Bean. Xyviewpointerbean;import Bean.    Xyviewtextbean;public class Mainactivity extends Activity {private Xyview xyview;        @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Initcache ();        Initview ();    InitData (); } private void Initcache () {} private void Initview () {Xyview = (Xyview) Findviewbyid (R.id.main_page_vie    W_xyview); } private void InitData () {//First point XyviewpointerbeAn xypointer = new Xyviewpointerbean ();        Float data[] = {10.0f, 20.0f, -10.0f, 40.0f, 20.0f, 50.0f};        Xypointer.setdata (data);        Xypointer.setcolor (color.red);        Xypointer.setstrokewidth (20.0f);        Xyviewdrawpointer xyviewdrawpointer = new Xyviewdrawpointer (xypointer);        Xyview.addxyviewdrawable (Xyviewdrawpointer);        Drawing Xyviewbitmapbean Xybitmap = new Xyviewbitmapbean ();        Float databitmap[] = {10.0f, 20.0f, -10.0f, 40.0f, 20.0f, 50.0f};        drawable d = getresources (). getdrawable (R.drawable.weather_temperature_point_icon_high);        bitmapdrawable BD = (bitmapdrawable) D;        Bitmap B = Bd.getbitmap ();        Bitmap[] bs = {b, b, B, B, B, b};        Xybitmap.sety_away (40);        Xybitmap.setdata (DATABITMAP);        Xybitmap.setbitmapdata (BS);        Xyviewdrawbitmap Xyviewdrawbitmap = new Xyviewdrawbitmap (XYBITMAP);        Xyview.addxyviewdrawable (XYVIEWDRAWBITMAP); First line Xyviewlinebean XYlinebean = new Xyviewlinebean ();        Xylinebean.setdata (data);        Xylinebean.setcolor (Color.Black);        Xylinebean.setstrokewidth (2.0f);        Xyviewdrawline xyviewline = new Xyviewdrawline (Xylinebean);        Xyview.addxyviewdrawable (Xyviewline);        Xyviewtextbean xytexter = new Xyviewtextbean ();        Float datatext[] = {10.0f, 20.0f, -10.0f, 40.0f, 20.0f, 50.0f};        String [] datastrs={"Dava", "Two Dolls", "Three Dolls", "Four Dolls", "Five Dolls", "Six Dolls"};        Xytexter.setdata (Datatext);        Xytexter.setcolor (color.red);        Xytexter.setstrokewidth (1.0f);        Xytexter.settextsize (18.0f);        Xytexter.settextdata (Datastrs);        Xyviewdrawtext xyviewtexter = new Xyviewdrawtext (xytexter);    Xyview.addxyviewdrawable (Xyviewtexter); @Override public boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.activity_main, M        ENU);    return true; }}
The jar package used in the code is uploaded to my resources, please download it if you have any request.


Android Trend chart creation and use

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.