0

我需要格式化 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)了,但后来所有的标签都一样了......

4

1 回答 1

0

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

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

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

于 2015-04-11T18:00:32.500 回答