【文件属性】:
文件名称:android折线图
文件大小:2.2MB
文件格式:RAR
更新时间:2017-04-01 11:34:58
折线图
package com.yzxy.draw;
002
003 import java.util.ArrayList;
004 import java.util.HashMap;
005 import java.util.Iterator;
006 import java.util.Map;
007 import java.util.Set;
008
009 import android.annotation.SuppressLint;
010 import android.content.Context;
011 import android.graphics.Canvas;
012 import android.graphics.Color;
013 import android.graphics.Paint;
014 import android.graphics.Path;
015 import android.graphics.Point;
016 import android.graphics.RectF;
017 import android.graphics.Paint.Style;
018 import android.graphics.Typeface;
019 import android.util.AttributeSet;
020 import android.view.MotionEvent;
021 import android.view.View;
022
023 /**
024 *
025 * @author zhangyayun1@gmail.com
026 *
027 */
028 @SuppressLint("ViewConstructor")
029 class MyChartView extends View{
030
031 public static final int RECT_SIZE = 10;
032 private Point mSelectedPoint;
033
034 //枚举实现坐标桌面的样式风格
035 public static enum Mstyle
036 {
037 Line,Curve
038 }
039
040 private Mstyle mstyle=Mstyle.Line;
041 private Point[] mPoints = new Point[100];
042
043 Context context;
044 int bheight=0;
045 HashMap map;
046 ArrayList dlk;
047 int totalvalue=30;
048 int pjvalue=5;
049 String xstr,ystr="";//横纵坐标的属性
050 int margint=15;
051 int marginb=40;
052 int c=0;
053 int resid=0;
054 Boolean isylineshow;
055
056 /**
057 * @param map 需要的数据,虽然key是double,但是只用于排序和显示,与横向距离无关
058 * @param totalvalue Y轴的最大值
059 * @param pjvalue Y平均值
060 * @param xstr X轴的单位
061 * @param ystr Y轴的单位
062 * @param isylineshow 是否显示纵向网格
063 * @return
064 */
065 public void SetTuView(HashMap map,int totalvalue,int pjvalue,String xstr,String ystr,Boolean isylineshow)
066 {
067 this.map=map;
068 this.totalvalue=totalvalue;
069 this.pjvalue=pjvalue;
070 this.xstr=xstr;
071 this.ystr=ystr;
072 this.isylineshow=isylineshow;
073 //屏幕横向
074 // act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
075 }
076
077 public MyChartView(Context ct)
078 {
079 super(ct);
080 this.context=ct;
081 }
082
083 public MyChartView(Context ct, AttributeSet attrs)
084 {
085 super( ct, attrs );
086 this.context=ct;
087 }
088
089 public MyChartView(Context ct, AttributeSet attrs, int defStyle)
090 {
091 super( ct, attrs, defStyle );
092 this.context=ct;
093 }
094
095 @SuppressLint("DrawAllocation")
096 @Override
097 protected void onDraw(Canvas canvas) {
098 super.onDraw(canvas);
099 if(c!=0)
100 this.setbg(c);
101 if(resid!=0)
102 this.setBackgroundResource(resid);
103 dlk=getintfrommap(map);
104 int height=getHeight();
105 if(bheight==0)
106 bheight=height-marginb;
107
108 int width=getWidth();
109 int blwidh=dip2px(context,50);
110 int pjsize=totalvalue/pjvalue;//界面布局的尺寸的比例
111 // set up paint
112 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
113 paint.setColor(Color.GRAY);
114 paint.setStrokeWidth(1);
115 paint.setStyle(Style.STROKE);
116 for(int i=0;i xlist=new ArrayList();//记录每个x的值
124 //画直线(纵向)
125 paint.setColor(Color.GRAY);
126 if(dlk==null)
127 return;
128 for(int i=0;i dlk,HashMap map,ArrayList xlist,int max,int h)
239 {
240 Point[] points=new Point[dlk.size()];
241 for(int i=0;i getintfrommap(HashMap map)
281 {
282 ArrayList dlk=new ArrayList();
283 int position=0;
284 if(map==null)
285 return null;
286 Set set= map.entrySet();
287 Iterator iterator = set.iterator();
288
289 while(iterator.hasNext())
290 {
291 @SuppressWarnings("rawtypes")
292 Map.Entry mapentry = (Map.Entry)iterator.next();
293 dlk.add((Double)mapentry.getKey());
294 }
295 for(int i=0;i getMap() {
325 return map;
326 }
327
328 public void setMap(HashMap map) {
329 this.map = map;
330 }
331
332 public int getTotalvalue() {
333 return totalvalue;
334 }
335
336 public void setTotalvalue(int totalvalue) {
337 this.totalvalue = totalvalue;
338 }
339
340 public int getPjvalue() {
341 return pjvalue;
342 }
343
344 public void setPjvalue(int pjvalue) {
345 this.pjvalue = pjvalue;
346 }
347
348 public String getXstr() {
349 return xstr;
350 }
351
352 public void setXstr(String xstr) {
353 this.xstr = xstr;
354 }
355
356 public String getYstr() {
357 return ystr;
358 }
359
360 public void setYstr(String ystr) {
361 this.ystr = ystr;
362 }
363
364 public int getMargint() {
365 return margint;
366 }
367
368 public void setMargint(int margint) {
369 this.margint = margint;
370 }
371
372 public Boolean getIsylineshow() {
373 return isylineshow;
374 }
375
376 public void setIsylineshow(Boolean isylineshow) {
377 this.isylineshow = isylineshow;
378 }
379
380 public int getMarginb() {
381 return marginb;
382 }
383
384 public void setMarginb(int marginb) {
385 this.marginb = marginb;
386 }
387
388 public Mstyle getMstyle() {
389 return mstyle;
390 }
391
392 public void setMstyle(Mstyle mstyle) {
393 this.mstyle = mstyle;
394 }
395
396 public int getBheight() {
397 return bheight;
398 }
399
400 public void setBheight(int bheight) {
401 this.bheight = bheight;
402 }
403
404 public int getC() {
405 return c;
406 }
407
408 public void setC(int c) {
409 this.c = c;
410 }
411
412 public int getResid() {
413 return resid;
414 }
415
416 public void setResid(int resid) {
417 this.resid = resid;
418 }
419
420
421
422 }
【文件预览】:
MainActivity
----bin()
--------classes.dex(867KB)
--------res()
--------jarlist.cache(120B)
--------dexedLibs()
--------classes()
--------resources.ap_(30KB)
--------MainActivity.apk(343KB)
--------AndroidManifest.xml(1KB)
----res()
--------drawable-ldpi()
--------menu()
--------drawable-hdpi()
--------drawable-xhdpi()
--------values()
--------drawable-mdpi()
--------layout()
----proguard-project.txt(781B)
----ic_launcher-web.png(54KB)
----assets()
----gen()
--------com()
----.settings()
--------org.eclipse.core.resources.prefs(88B)
--------org.eclipse.core.runtime.prefs(81B)
--------org.eclipse.jdt.core.prefs(177B)
----src()
--------com()
----.project(840B)
----.classpath(466B)
----project.properties(563B)
----AndroidManifest.xml(1KB)
----libs()
--------armeabi()
--------android-support-v4.jar(377KB)
--------jpush-sdk-release1.3.6.jar(220KB)