The program works well in Windows 7, but it goes wrong in Windows 10.
Can't figure out what the problem is?
procedure SubChart_SizePostion(var TheChart, SubChart: TChart);
const
SubChartToEdge = 0;
MinSizeRatio = 0.3;
var
tmpMin, tmpMax, SubHorizRange, SubVertRange, SubXYScreen, SubHorizAxisScale, SubVertAxisScale, SubOffset: Double;
SubLeft, SubTop, SubRight, SubBottom, SubChartWidth, SubChartHeight: integer;
begin
if (TheChart = nil) or (SubChart = nil) then { 双图 }
exit;
with TheChart do
begin
if (ChartWidth > 0) and (ChartHeight > 0) and (SeriesCount > 0) then
begin
with Series[0] do
begin
with GetHorizAxis do
SubHorizRange := Maximum - Minimum;
with GetVertAxis do
SubVertRange := Maximum - Minimum;
SubXYScreen := GetXYScreen(TheChart);
SubHorizAxisScale := (SubHorizRange / ChartWidth);
SubVertAxisScale := (SubVertRange / ChartHeight) * SubXYScreen;
end;
with SubChart.Series[0].GetHorizAxis do
begin
Automatic := true;
CalcMinMax(tmpMin, tmpMax);
SetMinMax(tmpMin, tmpMax);
SubHorizRange := Maximum - Minimum;
SubChartWidth := Round(SubHorizRange / SubHorizAxisScale);
if SubChartWidth / ChartWidth < MinSizeRatio then
SubChartWidth := Round(ChartWidth * MinSizeRatio);
SubOffset := (SubHorizAxisScale * SubChartWidth - SubHorizRange) / 2.0;
SetMinMax(tmpMin - SubOffset, tmpMax + SubOffset);
Increment := Series[0].GetHorizAxis.Increment;
end;
with SubChart.Series[0].GetVertAxis do
begin
Automatic := true;
CalcMinMax(tmpMin, tmpMax);
SetMinMax(tmpMin, tmpMax);
SubVertRange := Maximum - Minimum;
SubChartHeight := Round(SubVertRange / SubVertAxisScale);
if SubChartHeight / ChartHeight < MinSizeRatio then
SubChartHeight := Round(ChartHeight * MinSizeRatio);
SubOffset := (SubVertAxisScale * SubChartHeight / SubXYScreen - SubVertRange) / 2.0;
SetMinMax(tmpMin - SubOffset, tmpMax + SubOffset);
Increment := Series[0].GetVertAxis.Increment;
end;
SubRight := ChartRect.Right - SubChartToEdge;
SubTop := ChartRect.Top + SubChartToEdge;
SubLeft := SubRight - SubChartWidth;
SubBottom := SubTop + SubChartHeight;
with SubChart do
begin
CustomChartRect := true;
ChartRect := TeeRect(SubLeft, SubTop, SubRight, SubBottom);
end;
end;
end;
end;