Steema TeeChart Xamarin Forms - X 轴日期时间标签
Steema TeeChart Xamarin Forms - X axis DateTime labels
我正在使用 Steema TeeChart 构建烛台图表。
我有这个 class 的数据:
public class Candles
{
public DateTime date { get; set; }
public double open { get; set; }
public double high { get; set; }
public double low { get; set; }
public double close { get; set; }
public Candles (long date, double open, double high, double low, double close)
{
this.date = epoch2string(date/1000000);
this.open = open;
this.high = high;
this.low = low;
this.close = close;
}
public Candles(int date)
{
this.date = epoch2string(date);
}
private DateTime epoch2string(long epoch) {
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(epoch);
}
}
我正在循环添加数据:
foreach (var item in candleList) {
chartStyle.Add (item.open, item.high, item.low, item.close);
}
但是我应该如何将 class 的 "date" 值添加为 X 轴上的标签?
将日期作为 DateTime 值添加到每个蜡烛会自动执行此操作,例如:
Steema.TeeChart.Styles.Candle candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
DateTime date = DateTime.Now;
Random tmp = new Random();
for (int i = 0; i < 10; i++)
{
double open = tmp.Next();
double high = tmp.Next();
double low = tmp.Next();
double close = tmp.Next();
candle1.Add(date.AddDays(i), open, high, low, close);
}
你的情况应该是:
foreach (var item in candleList) {
chartStyle.Add (item.date, item.open, item.high, item.low, item.close);
}
根据某些图表设置,这可能不是自动的,在这种情况下,您可以强制这样做:
candle1.XValues.DateTime = true;
tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MMM";
基于我的示例代码。
如果您想将日期添加为文本标签并删除周末间隔,您可以使用 RemoveGaps property or as shown in the All Features\Welcome !\Chart styles\Financial\Candle (OHLC)\Axis Labels no Weekends example at the features demo included with TeeChart for .NET. I posted an example based on the mentiond demo here。
我正在使用 Steema TeeChart 构建烛台图表。 我有这个 class 的数据:
public class Candles
{
public DateTime date { get; set; }
public double open { get; set; }
public double high { get; set; }
public double low { get; set; }
public double close { get; set; }
public Candles (long date, double open, double high, double low, double close)
{
this.date = epoch2string(date/1000000);
this.open = open;
this.high = high;
this.low = low;
this.close = close;
}
public Candles(int date)
{
this.date = epoch2string(date);
}
private DateTime epoch2string(long epoch) {
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(epoch);
}
}
我正在循环添加数据:
foreach (var item in candleList) {
chartStyle.Add (item.open, item.high, item.low, item.close);
}
但是我应该如何将 class 的 "date" 值添加为 X 轴上的标签?
将日期作为 DateTime 值添加到每个蜡烛会自动执行此操作,例如:
Steema.TeeChart.Styles.Candle candle1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
DateTime date = DateTime.Now;
Random tmp = new Random();
for (int i = 0; i < 10; i++)
{
double open = tmp.Next();
double high = tmp.Next();
double low = tmp.Next();
double close = tmp.Next();
candle1.Add(date.AddDays(i), open, high, low, close);
}
你的情况应该是:
foreach (var item in candleList) {
chartStyle.Add (item.date, item.open, item.high, item.low, item.close);
}
根据某些图表设置,这可能不是自动的,在这种情况下,您可以强制这样做:
candle1.XValues.DateTime = true;
tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MMM";
基于我的示例代码。
如果您想将日期添加为文本标签并删除周末间隔,您可以使用 RemoveGaps property or as shown in the All Features\Welcome !\Chart styles\Financial\Candle (OHLC)\Axis Labels no Weekends example at the features demo included with TeeChart for .NET. I posted an example based on the mentiond demo here。