C# TeeChart中箱线图系列的日期时间X轴
目前,我在TeeChart中添加了多个箱线图,如下所示:C# TeeChart中箱线图系列的日期时间X轴,c#,teechart,C#,Teechart,目前,我在TeeChart中添加了多个箱线图,如下所示: seriesIndex = 0; foreach(var dataGroup in DataGroups) //Each dataGroup contains all the ParameterValues at a specific point in time { var series = new Box() { ... } var values = dataGroup.ParameterValues; seri
seriesIndex = 0;
foreach(var dataGroup in DataGroups) //Each dataGroup contains all the ParameterValues at a specific point in time
{
var series = new Box() { ... }
var values = dataGroup.ParameterValues;
series.Add(seriesIndex, values);
seriesIndex++;
Chart.Series.Add(series);
}
我希望将其转换为X轴使用日期时间值(定义如下):
但是,Box类的Add方法不支持DateTime值。当我使用继承的(来自基系列类)Add(DateTime,double)方法(在foreach循环中)时,所有的DateTime值都变成了1899年12月31日上午12点的DateTime.toadate的基值。这让我相信我没有正确地将数据输入序列。谁能给我指一下正确的方向吗
所有的DateTime值都变为1899年12月31日上午12点,我认为这是DateTime.ToOADate的基值
没错,这就是TeeChart中垂直方框图的工作方式。X位置由其值确定,默认值为零。为了达到您的要求,您应该为每个方框图设置一个位置。这可以通过指定Position属性或通过来完成,如下面的代码段所示。对于日期时间标签,您可以将其设置为true,并让TeeChart自动计算标签,或者使用以下代码中显示的标签技巧:
tChart1.Aspect.View3D = false;
var boxSeries1 = new Steema.TeeChart.Styles.Box(tChart1.Chart);
var boxSeries2 = new Steema.TeeChart.Styles.Box(tChart1.Chart);
var boxSeries3 = new Steema.TeeChart.Styles.Box(tChart1.Chart);
boxSeries1.Add(DateTime.Now.AddDays(0).ToOADate(), new double[6] { 3, 6, 8, 15, 19, 21 });
boxSeries2.Add(DateTime.Now.AddDays(1).ToOADate(), new double[4] { 5, 7, 12, 21 });
boxSeries3.Add(DateTime.Now.AddDays(2).ToOADate(), new double[5] { 6, 7, 8, 15, 21 });
// A simple trick to force custom axis labels on bottom axis.
// In this case, series titles
Steema.TeeChart.AxisLabelsItems labels = tChart1.Axes.Bottom.Labels.Items;
labels.Clear();
foreach (Steema.TeeChart.Styles.Box b in tChart1.Series)
{
b.XValues.DateTime = true;
labels.Add(b.Position);
}
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy hh:mm";
所有的DateTime值都变为1899年12月31日上午12点,我认为这是DateTime.ToOADate的基值
没错,这就是TeeChart中垂直方框图的工作方式。X位置由其值确定,默认值为零。为了达到您的要求,您应该为每个方框图设置一个位置。这可以通过指定Position属性或通过来完成,如下面的代码段所示。对于日期时间标签,您可以将其设置为true,并让TeeChart自动计算标签,或者使用以下代码中显示的标签技巧:
tChart1.Aspect.View3D = false;
var boxSeries1 = new Steema.TeeChart.Styles.Box(tChart1.Chart);
var boxSeries2 = new Steema.TeeChart.Styles.Box(tChart1.Chart);
var boxSeries3 = new Steema.TeeChart.Styles.Box(tChart1.Chart);
boxSeries1.Add(DateTime.Now.AddDays(0).ToOADate(), new double[6] { 3, 6, 8, 15, 19, 21 });
boxSeries2.Add(DateTime.Now.AddDays(1).ToOADate(), new double[4] { 5, 7, 12, 21 });
boxSeries3.Add(DateTime.Now.AddDays(2).ToOADate(), new double[5] { 6, 7, 8, 15, 21 });
// A simple trick to force custom axis labels on bottom axis.
// In this case, series titles
Steema.TeeChart.AxisLabelsItems labels = tChart1.Axes.Bottom.Labels.Items;
labels.Clear();
foreach (Steema.TeeChart.Styles.Box b in tChart1.Series)
{
b.XValues.DateTime = true;
labels.Add(b.Position);
}
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yyyy hh:mm";