MPAndroidchart 教程:图例 Legend(七)
来源:互联网 发布:2017年网络热点 编辑:程序博客网 时间:2024/04/28 19:27
其余文章索引:
MPAndroidChart 教程:概述
MPAndroidChart 教程:开始 Getting Started(一)
MPAndroidChart 教程:与图表进行手势交互 Interaction with the Chart(二)
MPAndroidChart 教程:坐标轴,X轴,Y轴,Labels(三)
MPAndroidChart 教程:设置数据,设置颜色(四)
MPAndroidChart 教程:数据格式器 ValueFormatter(五)
MPAndroidChart 教程:图表的具体设置 Specific chart settings(六)
MPAndroidchart 教程:图例 Legend(七)
MPAndroidChart 教程:动态和实时数据 Dynamic & Realtime Data(八)
MPAndroidChart 教程:修改视窗 Modifying the Viewport(九)
MPAndroidChart 教程:动画 Animations(十)
MPAndroidChart 教程:MarkerView(十一)
MPAndroidChart 教程:ChartData类,ChartData子类, DataSet类,DataSet子类(十二)
时间仓促,难免有错误,有的话希望大家在评论中指出,谢谢。
源码:范例代码在线查看或下载
一、概述
本章将重点介绍各个图表类型特定的设置。
默认情况下,所有的图表类型都支持 Legend
且在设置图表数据后会自动生成 Legend
。 Legend
通常由一个标签的 形式/形状 来表示多个条目( entries
) 的每一个。
entries
数量自动生成的 legend 取决于DataSet 的标签 不同颜色的数量(在所有 DataSet
的对象)。 Legend
的标签取决于图表中所使用的 DataSet
对象。 如果没有为 DataSet
对象指定标签,图表将自动生成它们。 如果多个颜色用于一个 DataSet
,这些颜色分类 ,只通过一个标签说明。
对于定制的 Legend
,可以通过图表对象的 getLegend()
方法先获取 Legen
在进行调用对应方法:
Legend legend = chart.getLegend();
二、是否绘制 Legend
setEnabled(boolean enabled)
: 设置Legend启用或禁用。 如果禁用,Legend
将不会被绘制。
三、修改 Legend
setTextColor(int color)
: 设置图例标签的颜色。setTextSize(float size)
: 设置在DP传说标签的文字大小。
单位是”像素” min = 6f, max = 24f, default 10f
setTypeface(Typeface tf)
: 设置自定义Typeface图例标签。
四、Wrapping / clipping avoidance
setWordWrapEnabled(boolean enabled)
: 如果启用,Legend 的内容将不会超出图表边界之外,而是创建一个新的行。 请注意,这会降低性能和仅适用于”legend 位于图表下面”的情况。setMaxSizePercent(float maxSize)
: 设置最大图例的百分比(相对整个图表大小)。 默认值:0.95f(95%)
五、自定义 Legend
setPosition(LegendPosition pos)
: 通过 LegendPosition 设置 Legend 出现的位置。RIGHT_OF_CHART
RIGHT_OF_CHART_CENTER
RIGHT_OF_CHART_INSIDE
BELOW_CHART_LEFT
BELOW_CHART_RIGHT
BELOW_CHART_CENTER
PIECHART_CENTER
(PieChart独有
)等等。
setFormSize(float size)
: 设置 legend-forms 的大小,单位dp。setForm(LegendForm shape)
: 设置LegendForm
。This is the shape that is drawn next to the legend-labels with the color of the DataSet the legend-entry represents. 正方形,圆形或线。
legend.setFormSize(18f); legend.setForm(Legend.LegendForm.SQUARE); legend.setForm(Legend.LegendForm.CIRCLE); legend.setForm(Legend.LegendForm.LINE);
setXEntrySpace(float space)
: 设置在水平轴上legend-entries
的间隙。setYEntrySpace(float space)
: 设置在垂直轴上legend-entries
的间隙。setFormToTextSpace(float space)
: 设置legend-form
和legend-label
之间的空间。setWordWrapEnabled(boolean enabled)
: 设置 Legend 是否自动换行? 目前仅支持BelowChartLeft
,BelowChartRight
,BelowChartCenter
。 / you may want to set maxSizePercent when word wrapping, to set the point where the text wraps.
六、设置自定义标签和颜色
setCustom(int[] colors, String[] labels)
: 设置自定义Legend
的标签和颜色。 颜色数应该匹配标签数,并且相对应。A null label will start a group. A (-2) color will avoid drawing a form This will disable the feature that automatically calculates the legend labels and colors from the datasets. 调用resetCustom()
重新启用自动计算(and then notifyDataSetChanged() is needed to auto-calculate the legend again)。resetCustom()
: 调用此将禁用通过setCustom(...)
方法自定义的图例标签。在notifyDataSetChanged()
被调用后,标签将再次被自动计算。setExtra(int[] colors, String[] labels)
: Sets colors and labels that will be appended to the end of the auto calculated colors and labels arrays after calculating the legend. (if the legend has already been calculated, you will need to callnotifyDataSetChanged()
to let the changes take effect)
七、代码范例
Legend l = chart.getLegend(); l.setFormSize(10f); // set the size of the legend forms/shapes l.setForm(LegendForm.CIRCLE); // set what type of form/shape should be used l.setPosition(LegendPosition.BELOW_CHART_LEFT); l.setTypeface(...); l.setTextSize(12f); l.setTextColor(Color.BLACK); l.setXEntrySpace(5f); // set the space between the legend entries on the x-axis l.setYEntrySpace(5f); // set the space between the legend entries on the y-axis // set custom labels and colors l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "Set1", "Set2", "Set3", "Set4", "Set5" }); // and many more...
- MPAndroidchart 教程:图例 Legend(七)
- MPAndroidchart 教程:图例 Legend(七)
- 十一、基础教程-图例(Legend)
- legend图例
- echarts的legend图例的显示与隐藏(legend图例进入页面显示的个数)
- ggplot2--Legend(图例操作)
- HightChart图例(Legend)
- ggplot2-设置图例(legend)
- 显示图例(legend)
- Matlab如何创建多个Legend(图例)
- Arcgis 图例 esri.dijit.legend Legend widget
- ggplot2--legend图例的修改
- highcharts legend 饼图 图例位置
- ggplot2--legend图例的修改
- echarts 修改图例legend颜色
- android MPAndroidChart饼图实现图例后加数字或文本(定制图例)
- MPAndroidChart 教程:MarkerView(十一)
- MPAndroidChart 教程:MarkerView(十一)
- STL系列之一 deque双向队列
- 绪论-第1章-《数据结构习题集》答案解析-严蔚敏吴伟民版
- iOS 触摸 手势和tableView cell的点击冲突
- JavaScript-日期格式化(一)
- IO流
- MPAndroidchart 教程:图例 Legend(七)
- ZSTUOJ 4214: Power Eggs(经典动态规划——鹰蛋问题)
- C#下用Emgucv对图片进行灰度化、二值化、边缘检测、膨胀腐蚀运算、霍夫变换进行表格识别
- UVA 11136 (multiset||堆)
- Redis 的性能幻想与残酷现实
- JSP中获取HTML中的中文内容是乱码的解决方法---开发中遇到的问题
- HDU-2138-How many prime numbers(米勒拉宾素数测试)
- 回调函数
- android中的mvp模式(二)