I am trying to set the title for each of my graphs but for some reason I can only set the first graph’s title.
I am using an OOP approach, so I have the main.js
file which does all data manipulation and then creates a new object using a constructor function. That constructor function gets data and graph title (among other arguments). Then a method on constructor function creates the graph using those arguments.
For some reason, only the first graph is getting a title. And interestingly, it is getting the title associated with the last invocation of the constructor function using new
keyword.
Relevant code from main.js
:
slopeGraphKPK = new SlopeGraph(
"#chart1",
updatedKPKData,
dataKPKDomain,
provNameKPK
);
slopeGraphPunjab = new SlopeGraph(
"#chart2",
updatedPunjabData,
dataPunjabDomain,
provNamePunjab
);
slopeGraphICT = new SlopeGraph(
"#chart3",
updatedICTData,
dataICTDomain,
provNameICT
);
slopeGraphSindh = new SlopeGraph(
"#chart4",
updatedSindhData,
dataSindhDomain,
provNameSindh
);
slopeGraphBaloch = new SlopeGraph(
"#chart5",
updatedBalochData,
dataBalochDomain,
provNameBaloch
);
Code from mainSlopeGraph.js:
SlopeGraph = function(_parentElement, _someData, _someDomain, _provName) {
this.parentElement = _parentElement;
this.provData = _someData;
this.scaleDomain = _someDomain;
this.provName = _provName;
this.initVis();
};
SlopeGraph.prototype.initVis = function() {
let vis = this;
//START HERE: Only first shart is showing province name;
//and that is only the last one sent in from main.js
$("#provinceName").text(vis.provName);
// $("#provinceName").textContent = vis.provName;
// $("#provinceName").innerText = vis.provName;
// $("#provinceName").innerHTML = vis.provName;
//Other code that sets up axes etc...
.
.
.
}
I tried a bunch of different things but only un-commented out the one that is giving me the results described in this post. The rest resulted in no title at all. I was trying all these suggestions: https://www.w3schools.com/jsref/prop_node_textcontent.asp.
This is an old version of the code but will give an idea of the larger project, if that is helpful: https://github.com/SabahatPK/Data4Pakistan_SlopeGraphs
Thank you.