【发布时间】:2019-01-06 18:37:48
【问题描述】:
带有嵌入式 TeeChart 的 Delphi 10。 我想隐藏 tLineSeries 的一部分并仅检测 CalcClickedPart 的可见部分。
假设一条未排序的 XY 线之间有许多交叉点,用户可能会选择一些不可见的点。我通过将“隐藏”点的颜色设置为 clNone 来做到这一点。当用户移动鼠标时,在 MouseMove 事件中调用 CalcClickedPart,但它也是对“隐藏”点的响应,因为它不是真正的隐藏方式。
图表创建:
procedure TForm1.FormCreate(Sender: TObject);
const
clHideColor = {clDefault}clNone; // clNone, clDefault
begin
Chart1.View3D := false;
with Chart1.AddSeries(TLineSeries) as TLineSeries do
begin
// AddXY(Const AXValue, AYValue: TChartValue; Const ALabel: String; AColor: TColor):
XValues.Order := loNone;
YValues.Order := loNone;
AddXY( 0, 0, '', clHideColor); // Origin point
AddXY( 50, 50, '', clHideColor); // / Cross point
AddXY(100, 100); // /
AddXY(100, 0); // |
AddXY( 50, 50); // \ Cross point
AddXY( 0, 100); // \ End point
end;
end;
Chart 的 MouseMove 事件中的 CalcClickedPart 代码
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
Var
ClickedPart: tChartClickedPart;
sCursorText: string;
begin
sCursorText := '';
Chart1.CalcClickedPart(Point(X, Y), ClickedPart); // Return information about the TeeChart component below the Mouse pointer at an X,Y location.
Case ClickedPart.Part of
cpNone : sCursorText := 'cpNone';
cpLegend : sCursorText := 'cpLegend';
cpAxis : sCursorText := 'cpAxis';
cpSeries : sCursorText := 'cpSeries';
cpTitle : sCursorText := 'cpTitle';
cpFoot : sCursorText := 'cpFoot';
cpChartRect : sCursorText := 'cpChartRect';
cpSeriesMarks : sCursorText := 'cpSeriesMarks';
cpSeriesPointer : sCursorText := 'cpSeriesPointer' +
ClickedPart.PointIndex.ToString;
cpSubTitle : sCursorText := 'cpSubTitle';
cpSubFoot : sCursorText := 'cpSubFoot';
cpAxisTitle : sCursorText := 'cpAxisTitle';
end;
Chart1.Title.Text.Text := sCursorText;
end;
在上面的示例中,当鼠标在中间 (50,50) 时,显示的点是 #1(隐藏)而不是 4。 我可以遍历所有系列点并找到其他更接近的点,但是有没有一种“干净”的方法来隐藏部分系列?
【问题讨论】: