Hi, I am trying to draw veritcal line in my TGraph. My code compiles without error but the line is out of scope (picture attached for reference where you can see red line on bottom part). Can someone please help with the issue? Thank you.
void code() {
const Int_t nPoints = 5;
Double_t x[nPoints] = {1, 2, 3, 4, 5};
Double_t y[nPoints] = {2.0, 3.5, 1.5, 4.0, 2.5};
TGraph *graph = new TGraph(nPoints, x, y);
TCanvas *canvas = new TCanvas("canvas", "Graph Example", 800, 600);
graph->SetTitle("Example Graph");
graph->GetXaxis()->SetTitle("X-axis");
graph->GetYaxis()->SetTitle("Y-axis");
graph->Draw("APL"); // A: Axis, P: Points, L: Line
TLine *verticalLine = new TLine(2, canvas->GetUymin(), 2, canvas->GetUymax());
verticalLine->SetLineColor(kRed);
verticalLine->SetLineWidth(2);
verticalLine->Draw("same");
canvas->Draw();
}