这是设计的。这里的解决方案是使用自定义值。您可以通过将ListBox和TChart组件放在Form中并使用以下代码来查看差异:
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
bool automatic = true;
SetChart(new[] { 0.5685, 0.7141, 0.7301, 0.748, 0.7847, 1.2127 }, automatic);
SetChart(new[] { 0.5686, 0.7141, 0.7301, 0.748, 0.7847, 1.2127 }, automatic);
tChart1.Axes.Left.SetMinMax(0.55, 1.25);
}
private void SetChart(double[] values, bool auto)
{
var box = new Steema.TeeChart.Styles.Box(tChart1.Chart);
box.Add(tChart1.Series.Count, values);
if (auto)
{
box.ReconstructFromData();
listBox1.Items.Add("Series: " + box.Title.ToString());
listBox1.Items.Add("Median: " + box.Median.ToString());
listBox1.Items.Add("Quartile1: " + box.Quartile1.ToString());
listBox1.Items.Add("Quartile3: " + box.Quartile3.ToString());
listBox1.Items.Add("InnerFence1: " + box.InnerFence1.ToString());
listBox1.Items.Add("InnerFence3: " + box.InnerFence3.ToString());
listBox1.Items.Add("OuterFence1: " + box.OuterFence1.ToString());
listBox1.Items.Add("OuterFence3: " + box.OuterFence3.ToString());
listBox1.Items.Add("AdjacentPoint1: " + box.AdjacentPoint1.ToString());
listBox1.Items.Add("AdjacentPoint3: " + box.AdjacentPoint3.ToString());
listBox1.Items.Add("-------------------------");
}
else
{
box.UseCustomValues = !auto;
box.Median = 0.73905;
box.OuterFence1 = 0.0357;
box.OuterFence3 = 1.5337;
box.InnerFence1 = 0.3567;
box.InnerFence3 = 1.2127;
box.Quartile1 = 0.6777;
box.Quartile3 = 0.8917;
box.AdjacentPoint1 = box.YValues[0];
box.AdjacentPoint3 = 1.2127;
box.Median = 0.73905;
}
}
如果自动变量为真,您将看到自动计算的值,如下图所示:
将其设置为false将使用手动自定义值。要查看差异,您应该查看ReconstructFromData()方法是如何实现的(您可以使用反射器工具检查它):
/// <summary>
/// Reconstructs the box plot from series data
/// </summary>
public void ReconstructFromData()
{
int N = SampleValues.Count;
if (N > 0)
{
double InvN = 1.0 / N;
/* calculate median */
int med = N / 2;
if ((N % 2) == 0) median = 0.5 * (SampleValues[med - 1] + SampleValues[med]);
else median = SampleValues[med];
/* calculate Q1 && Q3 */
quartile1 = N > 1 ? Percentile(SampleValues, 0.25) : SampleValues[0];
quartile3 = N > 1 ? Percentile(SampleValues, 0.75) : SampleValues[0];
/* calculate IQR */
double iqr = quartile3 - quartile1;
innerFence1 = quartile1 - whiskerLength * iqr;
innerFence3 = quartile3 + whiskerLength * iqr;
/* find adjacent points */
int i;
for (i = 0; i <= med; i++) if (SampleValues[i] > innerFence1) break;
adjacentPoint1 = SampleValues[i];
for (i = med; i < N; i++) if (SampleValues[i] > innerFence3) break;
adjacentPoint3 = SampleValues[i - 1];
/* calculate outer fences */
outerFence1 = quartile1 - 2 * whiskerLength * iqr;
outerFence3 = quartile3 + 2 * whiskerLength * iqr;
}
}
在这里有所不同的是邻近点 3 。在第一个箱线图中,innerFence3与系列中的最后一个值重合,而在第二个箱线图中,它略小。因此,这段代码:
for (i = med; i < N; i++) if (SampleValues[i] > innerFence3) break;
adjacentPoint3 = SampleValues[i - 1];
比第一个系列提前一步,并且使用倒数第二个值而不是最后一个值。因此AdjacentPoint3和正在绘制的内容有所不同。
要自动计算数据,您可以执行以下操作:
box.ReconstructFromData();
box.UseCustomValues = true;
box.Median = box.Median;
box.OuterFence1 = box.OuterFence1;
box.OuterFence3 = box.OuterFence3;
box.InnerFence1 = box.InnerFence1;
box.InnerFence3 = box.InnerFence3;
box.Quartile1 = box.Quartile1;
box.Quartile3 = box.Quartile3;
box.AdjacentPoint1 = box.AdjacentPoint1;
box.AdjacentPoint3 = box.YValues[box.Count-1];
box.Median = box.Median;