简体   繁体   English

试图在X轴上添加日期 - GraphView for android

[英]Trying to add date in axis X - GraphView for android

I need some help, I want to show in my GraphView date by DD/MM/YYYY in axis x. 我需要一些帮助,我希望在轴X中通过DD / MM / YYYY在我的GraphView日期中显示。 And in the y axis number(Integer)... how can I add the date to the axis X it only get int. 并且在y轴号(整数)...如何将日期添加到轴X它只获得int。 (I use this library http://android-graphview.org/ ) (我使用这个库http://android-graphview.org/

There's a post about that topic in the documentation: 文档中有关于该主题的帖子:

http://www.android-graphview.org/documentation/label-formatter http://www.android-graphview.org/documentation/label-formatter

There is also a specific example for dates in axis - "Use Dates as Labels". 轴上的日期还有一个特定示例 - “将日期用作标签”。

If you set the X value as Date object or as unix epoch (millis from 1970-01-01) then you can easily use this predefined label formatter: 如果将X值设置为Date对象或unix epoch(millis from 1970-01-01),则可以轻松使用此预定义标签格式化程序:

graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity()));

You can use a custom list of horizontal labels, like this: 您可以使用自定义水平标签列表,如下所示:

barGraphView.setHorizontalLabels(new String[]{"1/1/1970", "1/2/1970", "1/3/1970"});

I did something similar by constructing the String array using a for-loop. 我通过使用for循环构造String数组做了类似的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM