TGraph() 3 arguments provided 0 needed

I was using TGraph to graph a simple quadratic y = x*x. This is my code:

#include <chrono>

#include <fstream>

//some ROOT includes

#include "TInterpreter.h"

#include "TROOT.h"

#include "TH1F.h"

#include "TH2S.h"

#include "TFile.h"

#include "TCanvas.h"

#include "TPad.h"

#include "TVectorD.h"

#include "TGraph.h"

using std::cin;

using std::cout;

using std::endl;


void vectorGraph()
{

    std::vector<Double_t> myX, myY;
    auto graph = new TCanvas("quadratic","graph");

    for (int i=0; i<20; i++)
    {

        myX.push_back((Double_t)i);
        myY.push_back((Double_t)i*i);
    }
    TGraph* quadGraph = new TGraph(20, myX,myY);
    quadGraph->Draw();
    graph->Draw();

but when i ran it on root MACROS the message I recieved was: requires 0 arguments, but 3 were provided
TGraph();


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Try:

TGraph *quadGraph = new TGraph(20, myX.data(), myY.data());
1 Like

awesome, that fixed it! Thanks!

is that because those are vectors? If i were just using arrays, would it work without calling for the data?

TGraph

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.