MPAndroidChart Library Wiki翻譯

——————————————–譯文—————————————

  1. 起步
  2. 交互
  3. Y轴
    YAxis是垂直轴数据和其他信息的容器类,每一个 Line-, Bar-, Scatter 和 CandleStickChart 都有一个左侧和右侧YAxis对象,分别负责左侧的Y轴和右侧的Y轴内容。雷达图(RadarChart) 只有一个YAxis. 每个Y轴都默认enabled,并且会被画出来。

可以对YAxis进行详细的样式设置,可设置项包含以下内容:
与Y轴对齐的标签(labels),包含Y轴的描述值。
Y轴,与上述标签平行。
栅格线(grid lines),每个Y轴标签都有相应的水平栅格线。
警戒线(LimitLines),与栅格线类似,用来设定特殊的边界或常值。
获取YAxis的实例,可以使用以下方法:
YAxis leftAxis = chart.getAxisLeft();
YAxis rightAxis = chart.getAxisRight();
YAxis leftAxis = chart.getAxis(AxisDependency.LEFT);
YAxis yAxis = radarChart.getYAxis(); // this method radarchart only
运行时,可以使用public AxisDependency getAxisDependency()获得图表某一侧Y轴。

控制Y轴的显示:
setEnabled(boolean enabled): 设置轴enabled 或 disabled. 如果 disabled, 轴的任何一部分都不会被画出。
setDrawAxisLine(boolean enabled): 设置轴线是否绘制。
setDrawGridLines(boolean enabled): 设置是否画出此轴对应的栅格线。
setDrawLabels(boolean enabled): 设置是否显示此轴对应的轴标签。
设定Y轴的样式:
setTextColor(int color): 设置轴标签字体的颜色。
setTextSize(float size):设置轴标签字体大小(单位dp)。
setTypeface(Typeface tf): 设置轴标签的个性化Typeface。
setGridColor(int color): 设置轴对应的栅格线颜色。
setGridLineWidth(float width): 设置轴对应的栅格线的粗细。
setAxisLineColor(int color): 设置轴线的颜色。
setAxisLineWidth(float width): 设置轴线的粗细。
个性化Y轴的值:
setStartAtZero(boolean enabled):如果enabled, Y轴始终从0开始。如果disabled,和下面的设置最小值配合使用。
setAxisMaxValue(float max): 设置Y轴最大值,设定之后不会自动计算图表数据的最大值。
resetAxisMaxValue(): 取消先前设置的最大值。这样做之候,会重新自动计算最大值。
setAxisMinValue(float min): 设置Y轴最小值。设定之后,不会自动计算最小值。
resetAxisMinValue(): 取消先前设置的最小值。这样做之候,会重新自动计算最小值。
setInverted(boolean enabled): 是否上下翻转Y轴。
setSpaceTop(float percent): Sets the top spacing (in percent of the total axis-range) of the highest value in the chart in comparison to the highest value on the axis.
setSpaceBottom(float percent): Sets the bottom spacing (in percent of the total axis-range) of the lowest value in the chart in comparison to the lowest value on the axis.
setShowOnlyMinMax(boolean enabled): 如果enabled,只显示最大值和最小值。
setPosition(YAxisLabelPosition pos): 设置轴标签与轴线的位置关系。 INSIDE_CHART 或 OUTSIDE_CHART可选。
Customizations that affect the value range of the axis need to be applied before setting data for the chart.

Y轴标签的个性化格式:
setValueFormatter(ValueFormatter f): 设置一个ValueFormatter给Y轴使用。
ValueFormatter接口允许用户格式化/修改原始的Y轴标签,返回一个格式化的文本。

个性值格式化栗子:

ValueFormatter
栗子:

MyFormatter的使用
警戒线(LimitLine):
YAxis支持使用LimitLine允许显示特殊的信息,比如边界线和常量等。以下是如何给YAxis添加LimitLines:

addLimitLine(LimitLine l): 给YAxis添加一个新的LimitLine。
removeLimitLine(LimitLine l): 移除YAxis上某个LimitLine。
More methods for adding / removing available as well.
警戒线 (class LimitLine) 是一种明显的、包含特殊信息的水平线,用来表达特殊的信息给用户。
比如说,你的图表可能会显示用户的多个血压测量值,为了提示用户超过140mmHg的舒张压是危险的,这时可以添加一条LimitLine提供相关信息。
栗子:

LimitLine的使用
4. X轴
XAxis class, 是和水平轴相关的一切数据和信息的容器类. 每一个Line-, Bar-, Scatter-, CandleStick- 和 RadarChart都有一个XAxis对象。XAxis会以ArrayList或String[]的形式显示ChartData中的对象。

XAxis允许设置不同的样式,包括以下方面:
X轴标签(labels),标签和水平轴线对齐,包括轴描述文字。
X轴轴线,与上述轴标签平行。
X轴的栅格线,与水平方向垂直。
获取XAxis实例,使用以下方法:
XAxisxAxis=chart.getXAxis();
控制XAxis哪部分显示:
setEnabled(boolean enabled): 设置XAxis enabled 或 disabled. 如果disabled, X轴的任何一部分都不会被画出来。
setDrawAxisLine(boolean enabled): 设置是否画出X轴线。
setDrawGridLines(boolean enabled): 设计是否画出X轴的栅格线。
setDrawLabels(boolean enabled): 设置是否显示X轴的标签。
修改设置XAxis样式:
setTextColor(int color): 设置X轴标签字体颜色。
setTextSize(float size): 设置X轴标签字体大小(单位dp)。
setTypeface(Typeface tf): 给X轴标签设定定制的Typeface。
setGridColor(int color): 设置X轴栅格线的颜色。
setGridLineWidth(float width): 设置X轴栅格线的粗细。
setAxisLineColor(int color): 设置X轴线的颜色。
setAxisLineWidth(float width): 设置X轴线的粗细。
定制XAxis标签值的格式:
setAdjustXLabels(boolean enabled): 设置是否自动调整X轴的标签。为true时,X轴的尺度变化时会自动调整标签。false时,X轴尺度变化时,标签不动。
setAvoidFirstLastClipping(boolean enabled): If set to true, the chart will avoid that the first and last axis label entry in the x-axis “clip” off the edge of the chart or the screen.
setSpaceBetweenLabels(int characters): Sets the space that should be left out between the x-axis labels in characters, default: 4.
setPosition(XAxisPosition pos): Sets the position where theXAxisshould appear. Choose between TOP, BOTTOM, BOTH_SIDED, TOP_INSIDE or BOTTOM_INSIDE.
栗子:

XAxis样式设置
5. 绑定数据
如果你想添加数据到图表中,请使用以下方法:

public void setData(ChartData data) {…}
上述方法中的参数类型是基类ChartData,它包含了绘制图表数据(Y轴和X轴的坐标之类的)时的所有信息。对于每种不同的图表类型,你应当使用ChartData对应的子类,比如LineChart对应的数据类型为LineData。所以在构造LineData给LineChart使用的时候,你可以使用以下方法:

// this is just one of many constructors
public LineData( ArrayList xVals, ArrayListsets) {…}
其中ArrayList xVals中的字符对应到X轴的标签labels。ArrayList

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值