使用 T 型图绘制大量箱线图(范围在 1 到 10,000 之间)
Plot very large number of box plots (range between 1 to 10,000) using Tee chart
我需要允许用户select开始和结束数据。一旦完成 selected,我需要获取这些日期之间的所有组数据并显示箱线图。问题是如果需要显示很多箱线图,箱线图会被覆盖。 T 形图不会自动缩小箱线图的大小。此外,不提供滚动条来调整底轴以适应所有箱线图。有什么解决办法吗?
您可以根据需要计算出合适的框宽。
这是一个简单的示例,其中包含 100 个框,可在缩放和取消缩放事件中调整它们的大小。
在 C# 中使用 TeeChart .NET
这里是代码:
private void testBoxPlotWidth()
{
tChart1.Aspect.View3D = false;
tChart1.Legend.Visible = false;
for (int i = 0; i < 100; i++)
{
Box b = new Box();
tChart1.Series.Add(b);
b.Position = i;
b.FillSampleValues();
b.ColorEach = true;
}
tChart1.Panning.Allow = ScrollModes.Horizontal;
tChart1.Zoom.Direction = ZoomDirections.Horizontal;
ReCalculateBoxWidth();
tChart1.Zoomed += TChart1_Zoomed;
tChart1.UndoneZoom += TChart1_UndoneZoom;
}
private void TChart1_UndoneZoom(object sender, EventArgs e)
{
ReCalculateBoxWidth();
}
private void TChart1_Zoomed(object sender, EventArgs e)
{
ReCalculateBoxWidth();
}
public void ReCalculateBoxWidth()
{
int boxW;
double tmpW;
tChart1.Draw();
tmpW = tChart1.Chart.ChartRect.Width / (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / 2;
tmpW = tmpW * 0.7;
boxW = (int)Math.Round(tmpW);
foreach (CustomBox b in tChart1.Series)
{
b.Box.SizeUnits = PointerSizeUnits.Pixels;
b.Box.HorizSize = boxW;
}
}
在 Delphi 使用 TeeChart VCL/FMX
这里是代码:
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.View3D:=False;
Chart1.Legend.Hide;
for i:=0 to 99 do
with Chart1.AddSeries(TBoxSeries) as TBoxSeries do
begin
Position:=i;
FillSampleValues;
end;
Chart1.AllowPanning:=pmHorizontal;
Chart1.Zoom.Direction:=tzdHorizontal;
RecalcBoxWidth;
end;
procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
RecalcBoxWidth;
end;
procedure TForm1.Chart1Zoom(Sender: TObject);
begin
RecalcBoxWidth;
end;
procedure TForm1.RecalcBoxWidth;
var i, boxW: Integer;
tmpW: Double;
begin
Chart1.Draw;
tmpW:=(Chart1.ChartRect.Right - Chart1.ChartRect.Left) / (Chart1.Axes.Bottom.Maximum - Chart1.Axes.Bottom.Minimum) / 2;
tmpW:=tmpW*0.9;
boxW:=Round(tmpW);
for i:=0 to 99 do
with Chart1[i] as TBoxSeries do
begin
Box.SizeUnits:=suPixels;
Box.Size:=boxW;
end;
Chart1.Draw;
end;
我在 C# 中使用了您的代码,但它没有调整框的宽度并且它们重叠。
private void button3_Click_1(object sender, EventArgs e)
{
tChart1.Aspect.View3D = false;
tChart1.Legend.Visible = false;
for(int i=0;i<100;i++)
{
Steema.TeeChart.Styles.Box b = new Steema.TeeChart.Styles.Box();
tChart1.Series.Add(b);
b.Position = i;
b.FillSampleValues();
}
tChart1.Panning.Allow = ScrollModes.Horizontal;
tChart1.Zoom.Direction = ZoomDirections.Horizontal;
ReCalculateBoxWidth();
}
public void ReCalculateBoxWidth()
{
int boxW;
double tmpW;
tChart1.Draw();
tmpW = (tChart1.Chart.ChartRect.Right - tChart1.Chart.ChartRect.Left) / (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / 2;
tmpW = tmpW * 0.9;
boxW = (int)Math.Round(tmpW);
foreach (Steema.TeeChart.Styles.CustomBox b in tChart1.Series)
{
b.Box.SizeUnits = Steema.TeeChart.Styles.PointerSizeUnits.Pixels;
b.Box.SizeDouble = boxW;
}
tChart1.Draw();
}
我需要允许用户select开始和结束数据。一旦完成 selected,我需要获取这些日期之间的所有组数据并显示箱线图。问题是如果需要显示很多箱线图,箱线图会被覆盖。 T 形图不会自动缩小箱线图的大小。此外,不提供滚动条来调整底轴以适应所有箱线图。有什么解决办法吗?
您可以根据需要计算出合适的框宽。
这是一个简单的示例,其中包含 100 个框,可在缩放和取消缩放事件中调整它们的大小。
在 C# 中使用 TeeChart .NET
这里是代码:
private void testBoxPlotWidth()
{
tChart1.Aspect.View3D = false;
tChart1.Legend.Visible = false;
for (int i = 0; i < 100; i++)
{
Box b = new Box();
tChart1.Series.Add(b);
b.Position = i;
b.FillSampleValues();
b.ColorEach = true;
}
tChart1.Panning.Allow = ScrollModes.Horizontal;
tChart1.Zoom.Direction = ZoomDirections.Horizontal;
ReCalculateBoxWidth();
tChart1.Zoomed += TChart1_Zoomed;
tChart1.UndoneZoom += TChart1_UndoneZoom;
}
private void TChart1_UndoneZoom(object sender, EventArgs e)
{
ReCalculateBoxWidth();
}
private void TChart1_Zoomed(object sender, EventArgs e)
{
ReCalculateBoxWidth();
}
public void ReCalculateBoxWidth()
{
int boxW;
double tmpW;
tChart1.Draw();
tmpW = tChart1.Chart.ChartRect.Width / (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / 2;
tmpW = tmpW * 0.7;
boxW = (int)Math.Round(tmpW);
foreach (CustomBox b in tChart1.Series)
{
b.Box.SizeUnits = PointerSizeUnits.Pixels;
b.Box.HorizSize = boxW;
}
}
在 Delphi 使用 TeeChart VCL/FMX
这里是代码:
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.View3D:=False;
Chart1.Legend.Hide;
for i:=0 to 99 do
with Chart1.AddSeries(TBoxSeries) as TBoxSeries do
begin
Position:=i;
FillSampleValues;
end;
Chart1.AllowPanning:=pmHorizontal;
Chart1.Zoom.Direction:=tzdHorizontal;
RecalcBoxWidth;
end;
procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
RecalcBoxWidth;
end;
procedure TForm1.Chart1Zoom(Sender: TObject);
begin
RecalcBoxWidth;
end;
procedure TForm1.RecalcBoxWidth;
var i, boxW: Integer;
tmpW: Double;
begin
Chart1.Draw;
tmpW:=(Chart1.ChartRect.Right - Chart1.ChartRect.Left) / (Chart1.Axes.Bottom.Maximum - Chart1.Axes.Bottom.Minimum) / 2;
tmpW:=tmpW*0.9;
boxW:=Round(tmpW);
for i:=0 to 99 do
with Chart1[i] as TBoxSeries do
begin
Box.SizeUnits:=suPixels;
Box.Size:=boxW;
end;
Chart1.Draw;
end;
我在 C# 中使用了您的代码,但它没有调整框的宽度并且它们重叠。
private void button3_Click_1(object sender, EventArgs e)
{
tChart1.Aspect.View3D = false;
tChart1.Legend.Visible = false;
for(int i=0;i<100;i++)
{
Steema.TeeChart.Styles.Box b = new Steema.TeeChart.Styles.Box();
tChart1.Series.Add(b);
b.Position = i;
b.FillSampleValues();
}
tChart1.Panning.Allow = ScrollModes.Horizontal;
tChart1.Zoom.Direction = ZoomDirections.Horizontal;
ReCalculateBoxWidth();
}
public void ReCalculateBoxWidth()
{
int boxW;
double tmpW;
tChart1.Draw();
tmpW = (tChart1.Chart.ChartRect.Right - tChart1.Chart.ChartRect.Left) / (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum) / 2;
tmpW = tmpW * 0.9;
boxW = (int)Math.Round(tmpW);
foreach (Steema.TeeChart.Styles.CustomBox b in tChart1.Series)
{
b.Box.SizeUnits = Steema.TeeChart.Styles.PointerSizeUnits.Pixels;
b.Box.SizeDouble = boxW;
}
tChart1.Draw();
}