每当单击鼠标左键时,我都使用 TCanvas 绘制一条蓝线,并在单击鼠标右键时绘制一条红线。目前,每当我单击图表上的另一条线时。我要做的是清除旧线,然后画一条新线。
下面是一些示例代码。
onClick 事件的代码
procedure TForm2.Chart1ChartClick(Sender: TJvChart; Button: TMouseButton;
Shift: TShiftState; X, Y, ChartValueIndex, ChartPenIndex: Integer;
var ShowHint, HintFirstLineBold: Boolean; HintStrs: TStrings);
begin
if Button = mbLeft then
begin
canvas.pen.color := clblue;
PlotHorizontal(X, Y);
end
else if Button = mbRight then
begin
Canvas.Pen.color := clred;
PlotHorizontal(X, Y);
end
结尾;
PlotHorizontal 过程
procedure TForm2.PlotHorizontal(X, Y : integer);
begin
with canvas do
begin
// draw the horizontal line
MoveTo(X, Y);
// without the 4 the line doesn't seem to reach the end of the graph
LineTo(X, Chart1.Options.XStartOffset -4);
MoveTo(X, Y);
LineTo(X, Chart1.Options.XStartOffset +
+ Chart1.Options.Yend);
end;
end;