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.