资讯专栏INFORMATION COLUMN

HelloCharts 使用总结

beanlam / 787人阅读

摘要:如图表控件对象。用来表示一组柱状图。饼状图注意,饼状图与其他图表不同的是,饼状图并没有轴,也不支持缩放。为了更好的显示效果,饼状图的布局宽高应相等。显示在内测,显示在外侧。默认值为,表示饼状图尽可能地占满整个控件。

HelloChart常见的API 一、主要的类

</>复制代码

  1. XXXValue:用来对单个的数据进行包装。如PointValue、SubcolumnValue;
    XXXChartData:图表的数据模型。如LineChartData、ColumnChartData;
    XXXChartView:图表控件对象。如LineChartView、ColumnChartView;
    PreviewXXXChartView:图表控件的预览控件。如PreviewLineChartView;
    Axis:坐标轴;
    Viewport:视图窗口,用来控制图表空间的缩放效果和显示。
二、通用的API

AbstractChartData //图表的数据模型抽象类。

</>复制代码

  1. setValueLabelBackgroundEnabled(boolean isValueLabelBackgroundEnabled):设置是否显示标签的背景
    setValueLabelBackgroundColor(int valueLabelBackgroundColor):设置标签背景颜色
    setValueLabelsTextColor(int valueLabelTextColor):设置标签文字颜色,默认为白色
    setValueLabelTextSize(int valueLabelTextSize):设置标签文字字号,默认为12sp
    setValueLabelTypeface(Typeface typeface):设置标签文字字体
    setValueLabelBackgroundAuto(boolean isValueLabelBackgrountAuto):设置是否自动绘制标签背景
    不使用自动绘制背景
    不使用自动绘制背景,会使用valueLabelBackgroundColor所设置的颜色,默认为灰色。
    使用自动绘制背景
    使用自动绘制背景,会使用Line的颜色作为标签背景色。
    setAxisXBottom(Axis axisX):在图表下方设置x轴
    setAxisYLeft(Axis axisY):在图表左侧设置y轴
    setAxisXTop(Axis axisX):在图表上方设置x轴
    setAxisYRight(Axis axisY):在图表右侧设置y轴

Axis

</>复制代码

  1. static generateAxisFromRange(float start, float stop, float step):生成从值startstop按照step等差的Axis轴对象。
    static generateAxisFromCollection(List axisValues):根据集合axisValues生成Axis轴对象。
    static generateAxisFromCollection(List axisValues, List axisValuesLabels):根据集合axisValues生成轴对象,axisValuesLabels作为轴坐标对应的标签。
    setValues(List values):设置该轴的坐标信息。
    setName(String name):设置轴的名称,默认为空不显示。
    setTextSize(int textSize):设置设置轴标签和名称的字号,默认为12sp。
    setTypeface(Typeface typeface):设置轴标签和名字的字体。
    setTextColor(int color):设置轴标签和名字的颜色。
    setAutoGenerated(boolean isAutoGenerated):设置是否自动生成轴对象,自动适应表格的范围。
    setHasLines(boolean hasLines):设置是否显示坐标网格。
    setLineColor(int lineColor):设置网格线的颜色。
    setInside(boolean isInside):设置是否将轴坐标的值显示在图表内侧。
    setInside的效果
    setMaxLabelChars(int maxLabelChars):设置轴标签可显示的最大字符个数,范围在0-32之间。
    setFormatter(AxisValueFormatter formatter):设置轴坐标格式化工具
    setHasSeparationLine(boolean hasSeparationLine):设置是否显示轴标签与图表之间的分割线

AxisValue //Axis轴坐标类。

</>复制代码

  1. setValue(float value):设置该轴坐标的值
    setLabel(String label):设置该轴坐标的标签

AbstractChartView //图表视图抽象类。

</>复制代码

  1. setInteractive(boolean isInteractive):设置该图表是否可交互。如不可交互,则图表不会响应缩放、滑动、选择或点击等操作。默认值为true,可交互。
    setZoomEnabled(boolean isZoomEnabled):设置是否可缩放。
    setScrollEnabled(boolean isScrollEnabled):设置是否可滑动。
    moveTo(float x, float y):将视图窗口(viewport)移动至指定位置。如果可以移动,viewport将以该点为视图的中心。
    moveToWithAnimation(float x, float y):以动画的形式移动viewport。
    setZoomType(ZoomType zoomType):设置缩放类型,可选的类型包括:ZoomType.HORIZONTAL_AND_VERTICAL, ZoomType.HORIZONTAL, ZoomType.VERTICAL,默认值为HORIZONTAL_AND_VERTICAL。
    setMaxZoom(float maxZoom):设置最大缩放比例。默认值20
    setZoomLevel(float x, float y, float zoomLevel):以坐标(x,y)为中心,自动缩放表格。注意,该方法应在设置完chartview的数据(chartdata)后再调用。
    setZoomLevelWithAnimation(float x, float y, float zoomLevel)
    setValueTouchEnabled(boolean isValueTouchEnabled):设置是否允许点击图标上的值,默认为true
    setMaximumViewport(Viewport maxViewport):设置最大化的viewport。注意,该方法应在设置完chartview的数据(chartdata)后再调用。
    setCurrentViewport(Viewport targetViewport):设置当前的viewport
    setCurrentViewportWithAnimation(Viewport targetViewport)
    resetViewports():重新计算最大化和当前viewport
    setValueSelectionEnabled(boolean isValueSelectionEnabled):设置是否可以选中图表中的值,即当点击图表中的数据值后,会一直处于选中状态,直到用户点击其他空间。默认为false
    selectValue(SelectedValue selectedValue):选中一个数据值
    setContainerScrollEnabled(boolean isContainerScrollEnabled, ContainerScrollType containerScrollType):设置是否允许图表在父容器中滑动。
    startDataAnimation():开始以动画的形式更新图表数据。
    startDataAnimation(long duration)
    cancelDataAnimation()
    setDataAnimationListener(ChartAnimationListener animationListener):设置数据动画的监听器
    setViewportCalculationEnabled(boolean isEnabled):设置是否允许在动画进行中或设置完表格数据后,自动计算viewport的大小。如果禁止,则需要可以手动设置。
    setViewportAnimationListener(ChartAnimationListener animationListener):设置viewport动画的监听器
    setViewportChangeListener(ViewportChangeListener viewportChangeListener):设置viewport发生变化的监听器

Viewport
通过left, top, right, bottom四边确定的一个矩形区域。用来控制视图窗口的缩放。

</>复制代码

  1. set(float left, float top, float right, float bottom):设置大小。
    leftright可以控制我们在x轴上想要显示哪部分数据,同理,top和bottom可以控制我们在y轴上要展示的数据。
    offset(float dx, float dy):使viewport发生偏移,dx为正数表示向右,dy为正数表示向下
    offsetTo(float newLeft, float newTop):使viewport偏移到指定位置,宽高不会改变
    inset(float dx, float dy):使viewport缩放,dx为正数会使viewport的宽边窄,dy为正数会使viewport的高度变长。即如果是正数,会放大所要显示的区域。
    contains(float x, float y):判断点(x,y)是否在viewport内
    contains(float left, float top, float right, float bottom):判断矩形是否在viewport内
    contains(Viewport v)

SelectedValue //用来保存选中的值的索引的包装类。

</>复制代码

  1. setFirstIndex(int firstIndex):设置第一个索引,如LineChart中表示第几条线的值(lineIndex)。
    setSecondIndex(int secondIndex):设置第二个索引,如LineChart中表示该条线上的第几个值(valueIndex)。
    setType(SelectedValueType type):设置类型。
    set(int firstIndex, int secondIndex, SelectedValueType type)
三、常用图表介绍

1、折线图Line

PointValue ------- //对“点”的封装类。

</>复制代码

  1. set(float x, float y):设置点的值
    setLabel(String label):点的标签信息

Line-------//对“线”的封装类

</>复制代码

  1. setColor(int color):线的颜色
    setPointColor(int pointColor):点的颜色
    setAreaTransparency(int areaTransparency):透明度?
    setStrokeWidth(int strokeWidth):线的粗细
    setPointRadius(int pointRadius):点的半径
    setHasPoints(boolean hasPoints):是否显示点
    setHasLines(boolean hasLines):是否显示线
    setHasLabels(boolean hasLabels):是否显示标签
    setHasLabelsOnlyForSelected(boolean hasLabelsOnlyForSelected):是否只有在点击“点”时才显示标签
    setCubic(boolean isCubic):是否是平滑曲线
    setSquare(boolean isSquare):是否以直角的形式显示线
    直角显示
    setFilled(boolean isFilled):是否对线的下方填充
    填充
    setShape(ValueShape shape):“点”的样式,默认提供ValueShape.CIRCLE(圆形)、ValueShape.SQUARE (方形)、ValueShape.DIAMOND(菱形)三种样式。
    setPathEffect(PathEffect pathEffect):线的路径效果
    路径效果
    setValues(List values):List集合,用来保存线上的每个点的信息。

LineChartData-----//折线图数据模型类。

</>复制代码

  1. setLines(List lines):设置所要展示的“线”
    setBaseValue(float baseValue):设置数据的初始值,即所有的数据从baseValue开始计算,默认值为0

LineChartView

</>复制代码

  1. setOnValueTouchListener(LineChartOnValueSelectListener touchListener):设置数据值点击监听。
    LineChartOnValueSelectListener需要实现onValueSelected(int lineIndex, int pointIndex, PointValue value)和onValueDeselected()两个监听回调方法。
    lineIndex表示点击的“线”的索引,pointIndex表示点击的“点”的索引,value表示该“点”的值。

PreviewLineChartView--------------//折线图的预览视图。

</>复制代码

  1. setPreviewColor(int color)

2、柱状图Column

SubcolumnValue--------------//用来保存子柱状图信息。

</>复制代码

  1. setValue(float value)

Column

</>复制代码

  1. 用来表示一组柱状图。一组柱状图可以分成多个子柱状图。
    setValues(List values):设置柱状图的数据内容。

ColumnChartData----------------//柱状图数据模型类。

</>复制代码

  1. setColumns(List columns):设置数据
    setStacked(boolean isStacked):设置是否将同一组的数据进行堆叠显示
    堆叠
    setFillRatio(float fillRatio):设置组与组之间的间隔比率。取值范围从0-11表示组与组之间不留任何间隔,0表示组之间会留有2px的间隔。
    setBaseValue(float baseValue)

ColumnChartView

</>复制代码

  1. setColumnChartData(ColumnChartData data):设置柱状图的数据
    setOnValueTouchListener(ColumnChartOnValueSelectListener touchListener):设置柱状图点击监听。

3、饼状图Pie
注意,饼状图与其他图表不同的是,饼状图并没有轴,也不支持缩放。为了更好的显示效果,饼状图的布局宽高应相等。

SliceValue----------//饼状图中“扇形”的数据模型。

</>复制代码

  1. setValue(float value):设置值
    setColor(int color):设置颜色
    setSliceSpacing(int sliceSpacing)
    setLabel(String label):设置标签

PieChartData----饼状图的数据模型

</>复制代码

  1. setValues(List values)
    setHasLabelsOutside(boolean hasLabelsOutside):设置是否将标签显示在饼状图外侧。False显示在内测,true显示在外侧。
    setHasCenterCircle(boolean hasCenterCircle):设置饼状图中心是否为空心圆
    setCenterCircleColor(int centerCircleColor):设置空心圆的颜色
    setCenterCircleScale(float centerCircleScale):设置空心圆的大小
    setCenterText1(String centerText1):设置饼状图中心的文字1
    setCenterText2(String centerText2)
    setCenterText1FontSize(int centerText1FontSize):设置饼状图中心文字1的大小
    setCenterText1Typeface(Typeface text1Typeface)
    setSlicesSpacing(int sliceSpacing):设置扇形之间的间距大小

PieChartView

</>复制代码

  1. setPieChartData(PieChartData data)
    setOnValueTouchListener(PieChartOnValueSelectListener touchListener)
    setChartRotation(int rotation, boolean isAnimated):设置饼状图旋转的角度
    setChartRotationEnabled(boolean isRotationEnabled):设置饼状图是否可以通过滑动来旋转
    setCircleFillRatio(float fillRatio):设置饼状图占用控件的比例,取值范围0-1。默认值为1,表示饼状图尽可能地占满整个控件。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/69295.html

相关文章

  • Android干货框架集锦,搭建项目必不可少

    摘要:最佳解析最佳解析最佳解析是一个依赖注入框架,由谷歌开发,最早的版本由公司开发。在对的介绍中指出,即,这里的即数据结构中的有向无环图。也就是说,是一个基于有向无环图结构的依赖注入库,因此的使用过程中不能出现循环依赖。 在开发过程中使用过很多优秀框架,比如网络的okhttp,图片的Fresco,注入的Gagger2等,都是非常优秀的框架。 所以今天在此介绍下至今本人知道的一些比较流行主流且...

    zhisheng 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<