0

每当单击鼠标左键时,我都使用 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

结尾;

PlotHorizo​​ntal 过程

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;
4

1 回答 1

0

通过保存画线位置的旧 X 和 Y 值,我能够让它工作。然后当再次单击鼠标时,我刷新了图表,并再次重新绘制了线条。

于 2013-06-26T11:59:19.627 回答