最後回答,但也許會對其他人有用。
我也很難過這個問題,特別是因爲我是Java初學者。 我實現了一個自定義的格式化程序。看起來有點醜陋的解決方案,但它的工作。思想如下:
- 採取僅Y軸爲值,並留下X軸作爲索引到一個數組(如Androidplot教程表明,使用ArrayFormat.Y_VALS_ONLY使用,// Y_VALS_ONLY意味着使用元素索引爲x值)
- 每次數據的變化,你需要傳遞給繪圖一個新的格式化您的新數據X軸
這裏有一些代碼段。
首先是轉換數組索引到一個自定義標籤字符串類:
public class MyIndexFormat extends Format {
public String[] Labels = null;
@Override
public StringBuffer format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) {
// try turning value to index because it comes from indexes
// but if is too far from index, ignore it - it is a tick between indexes
float fl = ((Number)obj).floatValue();
int index = Math.round(fl);
if(Labels == null || Labels.length <= index ||
Math.abs(fl - index) > 0.1)
return new StringBuffer("");
return new StringBuffer(Labels[index]);
}
這裏是我如何將其連接到劇情:
MyIndexFormat mif = new MyIndexFormat();
mif.Labels = // TODO: fill the array with your custom labels
// attach index->string formatter to the plot instance
pricesPlot.getGraphWidget().setDomainValueFormat(mif);
這招作品也爲動態更新。
注意:Androidplot在繪製水平線時似乎有問題,所以如果您的數據具有相同的Y值,您可能會得到奇怪的結果,我已經在此問題上尋求幫助。
非常感謝馬丁:) – K1988
謝謝偉大的作品 –
@Martin在水平線上的任何問題?對於那些不知道的人來說,如果你畫出一條水平線(比如說一個圖的y值都是0),那麼這個圖不會顯示在圖上,但是如果你有另一個不是水平線的圖,水平線會顯示出來。 – whyoz