TeeChart 中箱线图系列的日期时间 X 轴
Datetime X-axis for Boxplot series in 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;
series.Add(seriesIndex, values);
seriesIndex++;
Chart.Series.Add(series);
}
我想转换它以便 X 轴使用 DateTime 值(定义如下):
var timeIndex = dataGroup.TimeSeriesIndex;
但是,Box class 的 Add 方法不支持 DateTime 值。当我使用继承的(来自基础系列 class)Add(DateTime, double)
方法(在 foreach 循环内)时,所有 DateTime 值都变为 12 AM December 31, 1899
,我认为这是 DateTime.ToOADate
。这让我相信我没有将数据正确输入到系列中。有人能给我指出正确的方向吗?
all the DateTime values become 12 AM December 31, 1899 which I recognize to be the base value for DateTime.ToOADate.
没错,这就是垂直箱形图在 TeeChart 中的工作方式。 X 位置由其 Position property, which is zero by default. To achieve what you request you should set a position for each box plot. This can be done assigning the Position property or via the specific add method override as shown in the code snippet below. For DateTime labels, you can just set XValues.DateTime 确定为 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";
目前,我在 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;
series.Add(seriesIndex, values);
seriesIndex++;
Chart.Series.Add(series);
}
我想转换它以便 X 轴使用 DateTime 值(定义如下):
var timeIndex = dataGroup.TimeSeriesIndex;
但是,Box class 的 Add 方法不支持 DateTime 值。当我使用继承的(来自基础系列 class)Add(DateTime, double)
方法(在 foreach 循环内)时,所有 DateTime 值都变为 12 AM December 31, 1899
,我认为这是 DateTime.ToOADate
。这让我相信我没有将数据正确输入到系列中。有人能给我指出正确的方向吗?
all the DateTime values become 12 AM December 31, 1899 which I recognize to be the base value for DateTime.ToOADate.
没错,这就是垂直箱形图在 TeeChart 中的工作方式。 X 位置由其 Position property, which is zero by default. To achieve what you request you should set a position for each box plot. This can be done assigning the Position property or via the specific add method override as shown in the code snippet below. For DateTime labels, you can just set XValues.DateTime 确定为 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";