Android custom trend chart

Source: Internet
Author: User

Android custom trend chart

In the past, there was a demand for a trend chart based on the Weekly Weather temperature. This chart is not based on XY coordinates, but a pure trend chart. Baidu later read some blogs, in general, there are some ideas. below is the overall trend chart:

The bottom line chart is the effect.

The following shows the sample code of the trend chart:

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. response);} private void initData () {// The first vertex XYViewPointerBean xyPointer = new XYViewPointerBean (); float data [] = {10.0f, 20366f,-10.0f, 40366f, 20366f, 50366f}; xyPointer. setData (data); xyPointer. setColor (Color. RED); xyPointer. setStrokeWidth (20366f); XYViewDrawPointer xyViewDrawPointer = new XYViewDrawPointer (xyPointer); xyview. addXYViewDrawable (writable); // draw XYViewBitmapBean xybitmap = new XYViewBitmapBean (); float dataBitmap [] = {10.0f, 20366f,-10.0f, 40366f, 20366f, 50366f }; drawable d = getResources (). getDrawable (R. drawable. weather_temperature_point_icon_high); BitmapDrawable bd = (BitmapDrawable) d; Bitmap B = bd. getBitmap (); Bitmap [] bs = {B, B}; xybitmap. setY_away (40); xybitmap. setData (dataBitmap); xybitmap. setBitmapData (bs); XYViewDrawBitmap xyViewDrawBitmap = new XYViewDrawBitmap (xybitmap); xyview. addXYViewDrawable (xyViewDrawBitmap); // The first line of 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, 20366f,-10.0f, 40366f, 20366f, 50366f }; string [] dataStrs = {"", ""}; 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, menu); return true ;}}
The jar package used in the Code is uploaded to my resources. If you want it, download and use it.


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.