Failed to set title of TGraph

Dear Experts

I want to set titles of graphs which I drawn on the same canvas, here is what I tried, but the title didn’t appear. Can you suggest me which procedure I’m missing?

root -l somefile.root

//in the root UI
Canvas* c = new TCanvas();
//code below was in a single line, but for easier reading I put them different lines
for(int i=0; i<8; ++i){ 
    c->cd(i+1); gPad->DrawFrame(0, -0.7, 1000, 0.2);
    t->Draw(Form("vol_%d:Iteration$", i+1), "", "LSAME", 1, 0); 
    auto graph = (TGraph*)gPad->GetPrimitive("Graph"); 
    graph->SetTitle(Form("waveform ch.%d", i)); 
    graph->GetYaxis()->SetTitle("Voltage [V]"); 

gPad->DrawFrame(0., -0.7, 1000., 0.2, TString::Format("waveform ch.%d;sample;Voltage [V]", i));

Didn’t know such elegant method! Thank you :slight_smile: