MPAndroidChart的具体属性方法
android中常用的第三方图表MPAndroidChart的一些具体属性及方法说明
注意:在将折线图转为曲线图时,lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);方法有的版本的jar包不能使用,
要设置lineDataSet.setDrawCubic(true);(默认是折线)
2 import android.app.Activity; 3 import android.graphics.Color; 4 import android.os.Bundle; 5 6 import com.github.mikephil.charting.charts.LineChart; 7 import com.github.mikephil.charting.components.Legend; 8 import com.github.mikephil.charting.components.LimitLine; 9 import com.github.mikephil.charting.components.XAxis; 10 import com.github.mikephil.charting.components.YAxis; 11 import com.github.mikephil.charting.data.Entry; 12 import com.github.mikephil.charting.data.LineData; 13 import com.github.mikephil.charting.data.LineDataSet; 14 15 import java.util.ArrayList; 16 17 public class MainActivity extends Activity { 18 19 private LineChart mLineChart; 20 private XAxis xAxis; //X坐标轴 21 private YAxis yAxis; //Y坐标轴 22 23 @Override 24 protected void onCreate(Bundle savedInstanceState) { 25 super.onCreate(savedInstanceState); 26 setContentView(R.layout.activity_main); 27 28 mLineChart = (LineChart) findViewById(R.id.chart); 29 30 xAxis = mLineChart.getXAxis(); 31 yAxis = mLineChart.getAxisLeft(); 32 33 LineData mLineData = getLineData(); 34 showChart(mLineChart, mLineData); 35 36 } 37 38 private void showChart(LineChart lineChart, LineData lineData) { 39 40 //General Chart Styling 通用的图表造型,还有些对于特定图表有这特定方法的造型。 41 //请参考https://github.com/PhilJay/MPAndroidChart/wiki/Specific-chart-settings 42 lineChart.setBackgroundColor(Color.argb(200, 173, 215, 210));// 设置图表背景 参数是个Color对象 43 44 lineChart.setDescription("setDescription我在这儿"); //图表默认右下方的描述,参数是String对象 45 lineChart.setDescriptionColor(Color.rgb(227, 135, 0)); //上面字的颜色,参数是Color对象 46 // lineChart.setDescriptionPosition(400f,600f); //上面字的位置,参数是float类型,像素,从图表左上角开始计算 47 // lineChart.setDescriptionTypeface(); //上面字的字体,参数是Typeface 对象 48 lineChart.setDescriptionTextSize(16); //上面字的大小,float类型[6,16] 49 50 lineChart.setNoDataTextDescription("没有数据呢(⊙o⊙)"); //没有数据时显示在中央的字符串,参数是String对象 51 52 lineChart.setDrawGridBackground(false);//设置图表内格子背景是否显示,默认是false 53 lineChart.setGridBackgroundColor(Color.rgb(256, 0, 0));//设置格子背景色,参数是Color类型对象 54 55 lineChart.setDrawBorders(true); //设置图表内格子外的边框是否显示 56 lineChart.setBorderColor(Color.rgb(236, 228, 126)); //上面的边框颜色 57 lineChart.setBorderWidth(20); //上面边框的宽度,float类型,dp单位 58 // lineChart.setMaxVisibleValueCount();设置图表能显示的最大值,仅当setDrawValues()属性值为true时有用 59 60 61 //Interaction with the Chart 图表的交互 62 63 //Enabling / disabling interaction 64 lineChart.setTouchEnabled(true); // 设置是否可以触摸 65 lineChart.setDragEnabled(true);// 是否可以拖拽 66 67 lineChart.setScaleEnabled(true);// 是否可以缩放 x和y轴, 默认是true 68 lineChart.setScaleXEnabled(true); //是否可以缩放 仅x轴 69 lineChart.setScaleYEnabled(true); //是否可以缩放 仅y轴 70 71 lineChart.setPinchZoom(true); //设置x轴和y轴能否同时缩放。默认是否 72 lineChart.setDoubleTapToZoomEnabled(true);//设置是否可以通过双击屏幕放大图表。默认是true 73 74 lineChart.setHighlightEnabled(false); //If set to true, highlighting/selecting values via touch is possible for all underlying DataSets. 75 lineChart.setHighlightPerDragEnabled(true);//能否拖拽高亮线(数据点与坐标的提示线),默认是true 76 77 lineChart.setAutoScaleMinMaxEnabled(false); 78 79 80 // Chart fling / deceleration 81 lineChart.setDragDecelerationEnabled(true);//拖拽滚动时,手放开是否会持续滚动,默认是true(false是拖到哪是哪,true拖拽之后还会有缓冲) 82 lineChart.setDragDecelerationFrictionCoef(0.99f);//与上面那个属性配合,持续滚动时的速度快慢,[0,1) 0代表立即停止。 83 84 85 //Highlighting programmatically 86 87 // highlightValues(Highlight[] highs) 88 // Highlights the values at the given indices in the given DataSets. Provide null or an empty array to undo all highlighting. 89 // highlightValue(int xIndex, int dataSetIndex) 90 // Highlights the value at the given x-index in the given DataSet. Provide -1 as the x-index or dataSetIndex to undo all highlighting. 91 // getHighlighted() 92 // Returns an Highlight[] array that contains information about all highlighted entries, their x-index and dataset-index. 93 94 95 //其他请参考https://github.com/PhilJay/MPAndroidChart/wiki/Interaction-with-the-Chart 96 //如手势相关方法,选择回调方法 97 98 99 // The Axis 坐标轴相关的,XY轴通用 100 xAxis.setEnabled(true); //是否显示X坐标轴 及 对应的刻度竖线,默认是true 101 xAxis.setDrawAxisLine(true); //是否绘制坐标轴的线,即含有坐标的那条线,默认是true 102 xAxis.setDrawGridLines(true); //是否显示X坐标轴上的刻度竖线,默认是true 103 xAxis.setDrawLabels(true); //是否显示X坐标轴上的刻度,默认是true 104 105 xAxis.setTextColor(Color.rgb(145, 13, 64)); //X轴上的刻度的颜色 106 xAxis.setTextSize(5); //X轴上的刻度的字的大小 单位dp 107 // xAxis.setTypeface(Typeface tf); //X轴上的刻度的字体 108 xAxis.setGridColor(Color.rgb(145, 13, 64)); //X轴上的刻度竖线的颜色 109 xAxis.setGridLineWidth(1); //X轴上的刻度竖线的宽 float类型 110 xAxis.enableGridDashedLine(40, 3, 0); //虚线表示X轴上的刻度竖线(float lineLength, float spaceLength, float phase)三个参数,1.线长,2.虚线间距,3.虚线开始坐标 111 112 113 //可以设置一条警戒线,如下: 114 LimitLine ll = new LimitLine(10f, "警戒线"); 115 ll.setLineColor(Color.RED); 116 ll.setLineWidth(4f); 117 ll.setTextColor(Color.GRAY); 118 ll.setTextSize(12f); 119 // .. and more styling options 120 xAxis.addLimitLine(ll); 121 122 123 // X轴专用 124 xAxis.setLabelsToSkip(1); //设置坐标相隔多少,参数是int类型 125 xAxis.resetLabelsToSkip(); //将自动计算坐标相隔多少 126 xAxis.setAvoidFirstLastClipping(true); 127 xAxis.setSpaceBetweenLabels(4); 128 xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);//把坐标轴放在上下 参数有:TOP, BOTTOM, BOTH_SIDED, TOP_INSIDE or BOTTOM_INSIDE. 129 130 // Y轴专用 131 yAxis.setStartAtZero(false); //设置Y轴坐标是否从0开始 132 yAxis.setAxisMaxValue(50); //设置Y轴坐标最大为多少 133 yAxis.resetAxisMaxValue(); //重新设置Y轴坐标最大为多少,自动调整 134 yAxis.setAxisMinValue(10); //设置Y轴坐标最小为多少 135 yAxis.resetAxisMinValue(); //重新设置Y轴坐标,自动调整 136 yAxis.setInverted(false); //Y轴坐标反转,默认是false,即下小上大 137 yAxis.setSpaceTop(0); //Y轴坐标距顶有多少距离,即留白 138 yAxis.setSpaceBottom(0); //Y轴坐标距底有多少距离,即留白 139 yAxis.setShowOnlyMinMax(false); //参数如果为true Y轴坐标只显示最大值和最小值 140 yAxis.setLabelCount(10, false); //第一个参数是Y轴坐标的个数,第二个参数是 是否不均匀分布,true是不均匀分布 141 yAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); //参数是INSIDE_CHART(Y轴坐标在内部) 或 OUTSIDE_CHART(在外部(默认是这个)) 142 // yAxis.setValueFormatter(YAxisValueFormatterf); 143 // Sets a custom ValueFormatter for this axis. This interface allows to format/modify 144 // the original label text and instead return a customized text. 145 146 147 // add data 148 lineChart.setData(lineData); // 设置数据 149 150 // get the legend (only possible after setting data) 151 Legend mLegend = lineChart.getLegend(); // 设置比例图标示,就是那个一组y的value的 152 153 // modify the legend ... 154 // mLegend.setPosition(LegendPosition.LEFT_OF_CHART); 155 mLegend.setForm(Legend.LegendForm.CIRCLE);// 样式 156 mLegend.setFormSize(2f);// 字体 157 mLegend.setTextColor(Color.WHITE);// 颜色 158 // mLegend.setTypeface(mTf);// 字体 159 160 lineChart.animateX(1000); // 立即执行的动画,x轴 161 } 162 163 private LineData getLineData() { 164 165 ArrayList<Entry> valsComp1 = new ArrayList<Entry>(); //坐标点的集合 166 ArrayList<Entry> valsComp2 = new ArrayList<Entry>(); 167 168 Entry c1e1 = new Entry(100.000f, 1); //坐标点的值,Entry(Y坐标,X坐标); 169 valsComp1.add(c1e1); 170 Entry c1e2 = new Entry(50.000f, 2); 171 valsComp1.add(c1e2); 172 173 Entry c2e1 = new Entry(30.000f, 1); //坐标点的值,Entry(Y坐标,X坐标); 174 valsComp2.add(c2e1); 175 Entry c2e2 = new Entry(80.000f, 3); 176 valsComp2.add(c2e2); 177 178 LineDataSet setComp1 = new LineDataSet(valsComp1, "Company"); //坐标线,LineDataSet(坐标点的集合, 线的描述或名称); 179 LineDataSet setComp2 = new LineDataSet(valsComp2, "Company"); 180 setComp1.setAxisDependency(YAxis.AxisDependency.LEFT); //以左边坐标轴为准 还是以右边坐标轴为基准 181 setComp2.setAxisDependency(YAxis.AxisDependency.LEFT); 182 183 ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); //坐标线的集合。 184 dataSets.add(setComp1); 185 dataSets.add(setComp2); 186 187 ArrayList<String> xVals = new ArrayList<String>(); //X坐标轴的值的集合 188 xVals.add("1.Q"); xVals.add("2.Q"); xVals.add("3.Q"); xVals.add("4.Q"); 189 xVals.add("1.Q"); xVals.add("2.Q"); xVals.add("3.Q"); xVals.add("4.Q"); 190 191 LineData data = new LineData(xVals, dataSets); //LineData(X坐标轴的集合, 坐标线的集合); 192 mLineChart.setData(data); //为图表添加 数据 193 mLineChart.invalidate(); // 重新更新显示 194 195 return data; 196 } 197 198 } 转自 : http://blog.csdn.net/ash_zheng/article/details/48712827
MPAndroidChart的具体属性方法相关推荐
- ES6语法~解构赋值、箭头函数、class类继承及属性方法、map、set、symbol、rest、new.target、 Object.entries......
2015年6月17日 ECMAScript 6发布正式版本 前面介绍基本语法, 后面为class用法及属性方法.set.symbol.rest等语法. 一.基本语法: 1. 定义变 ...
- ASP.NET基础教程-DataTable类对象-属性方法和事件
DataTable类对象可以表示表格,也可以在DataSet中存储多个DataTable对象. 该对象的属性方法和事件列表如下: 转载于:https://blog.51cto.com/chenxing ...
- js如何操作表格(常用属性方法汇总)
js如何操作表格(常用属性方法汇总) 一.总结 一句话总结: 二.表格相关的属性和方法 1.1 Table 对象集合 cells[] 返回包含表格中所有单元格的一个数组. 语法:tableObject ...
- 一个用户实体应该有它自己的实体验证,即一个实体应该有它的属性,方法,扩展属性及验证机制组成...
一个存储验证信息的公用类: /// <summary> /// 验证信息实体类 /// </summary> public class RuleV ...
- 静态方法、类方法、属性方法
静态方法:通过加@staticmethod实现,只是名义上归类管理,实际上在静态方法里访问不了类或实例中的任何属性. class Person(object):@staticmethoddef per ...
- python删除类方法_python中向类中动态添加新特性及删除属性方法
class Foo(object): pass obj = Foo() # 添加对象属性(对象名追加对象属性) obj.a = 100 # print(obj.a) # 添加类属性(类名称追加类属性) ...
- 使用proxy来调用未定义的属性方法
当我们调用一个函数的未定义属性时会报错.那么可以使用一个proxy拦截,并且传入dispatch函数,来使当调用未定义属性时,执行dispatch函数. 原理: 创建一个实例:function cre ...
- python中的os.mkdir和os.makedirs的使用区别,以及如何查看某个模块中的某些字母开头的属性方法
1 os.mkdir的使用 os.mkdir(dir_name):用于新建文件夹,当要新建的文件夹已经存在的时候,就会报错:FileExistsError: [Errno 17] File exist ...
- 【 iOS 应用开发 】 UIKit 控件 ( 代码生成控件 | UIView 属性方法 | Storyboard | Bundle | Property List | 动画 | 图片内存优化 )
文章目录 一. 代码生成控件 1. 创建设置项目 ( 1 ) 创建项目 ( ① 选择 Create a new Xcode project | ② 创建 Single View Application ...
最新文章
- android单个页面切换_MTransition是一个Android上的页面切换动画库
- esp32 cam工作电流_我如何在家工作:Cam的生产力之痛
- gulp入坑系列(1)——安装gulp
- 程序员求职面试丨面试必备之终极指导篇,掌握这些,面试不再困难!
- 黑客编程为什么首选Python语言?这个高速你答案!
- linux内核模块的程序结构
- 乌班图配置mysql Java_从零开始的告警平台(1)
- 打包的时候不把配置文件加进去_苹果软件打包签名原理
- flash电脑安装包_Flash动画制作,Animate CC 2019下载安装
- keil ISIS AT89C51单片机
- steam账号被盗找回概率_如何找回忘记的Steam密码
- 刷脸支付系统源码定制开发
- ppt制作弹跳的小球动画效果_PPT动画制作教程:小球弹跳动画
- 阿里云跨账号迁移云服务器实例
- 控制器双活 负载均衡
- 计算机网恢,电脑附身
- 30岁转行做程序员是一种怎样的体验?
- HTTPError错误
- 清除xp,win7快捷方式小箭头
- mysql数据库考试好考吗_MySQL数据库考试试题及答案