AndroidPlot:在X轴设置标签 [英] AndroidPlot : setting the labels on the X-axis
问题描述
随着AndroidPlot网站是下来,我有点卡住了在这个问题上。几个类似的问题已经被问过,但他们没有得到适当的回答,所以在这里我走了。
With the AndroidPlot website being down, I'm kind of stuck on this issue. Several similar questions have been asked, but none of them were properly answered, so here I go.
我想知道我可以重新标记我的X轴。例如,如果我想绘制了解每月的数据值,我会绘制它像(1,82)
为Januari,(2,67)
为Februari,等等。后来,我想在X-标签从改变[1,2,3,...]
到 x_labels = [Januari, Februari,...]
。我怎样才能做到这一点?
I would like to know how I can relabel my X-axis. For example, if I want to plot values about monthly data, I would plot it like (1, 82)
for Januari, (2,67)
for Februari , and so on. Afterwards, I want to change the X-labels from [1, 2, 3, ...]
to x_labels = ["Januari", "Februari", ...]
. How can I do this?
哦,并请提供答案而 x_labels
可以是任何东西(如果有每月标签的一些具体方法,你永远不知道)。
Oh and please provide an answer for which x_labels
can be anything (in case there is some specific method for monthly labels, you never know).
任何人谁可以帮助?
谢谢!
Anyone who could help? Thanks!
推荐答案
想通了自己:
this.getGraphWidget().setDomainValueFormat(new GraphXLabelFormat());
// ...
private class GraphXLabelFormat extends Format {
private static LABELS = ["Label 1", "Label 2", "Label 3"];
@Override
public StringBuffer format(Object object, StringBuffer buffer, FieldPosition field) {
int parsedInt = Math.round(Float.parseFloat(object.toString()));
String labelString = = LABELS[parsedInt];
buffer.append(labelString);
return buffer;
}
@Override
public Object parseObject(String string, ParsePosition position) {
return java.util.Arrays.asList(LABELS).indexOf(string);
}
}
这篇关于AndroidPlot:在X轴设置标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!