Oxyplot BarSeries格式功能

时间:2014-12-05 14:07:48

标签: oxyplot

我需要格式化BarItem中的标签,使其具有时间格式,如00:10。 我正在使用BarSeries.Format函数,但如果我不使用BarSeries.LabelFormatString,则标签不会显示,如果我使用LabelFormatString,则所有标签都将具有相同的格式/值。

这是我的代码:

BarItem baritem = new BarItem {Value = 10};  //in seconds
Object[] time = new object[2];
time [0] = "00";
time [1] = "10";
barSeries.Format("{0}:{1}",baritem,time);

使用此代码,它不显示任何标签。使用barSeries.LabelFormatString = "{0}"显示10.

我已经尝试了barSeries.LabelFormatString = barSeries.Format("{0}:{1}",baritem,time),但随后所有标签都变得相同......

1 个答案:

答案 0 :(得分:0)

对于遇到同样问题的人来说,解决方案很简单,只需将BarItem类子类化,如下所示:

class TimeBarItem : BarItem {
  public TimeSpan Time { get { return TimeSpan.FromSeconds(this.Value); } }
}

之后我们可以这样做: barSeries.LabelFormatString = "{Time}"