Hello everyone,
I am having some trouble overriding the old pie chart data with new one. Any help or pointers would be greatly appreciated.
So currently everything is working fine. But when I click on a feature to get the new attributes and use that attributes to input into the existing pie chart. I expect and wanted to make the old pie chart graphic disappear and the new one appear in its place with the new attributes/values reflect. But instead of that, I got another pie chart added on right underneath the old one. See the attached code, any idea on how to resolve this? Thanks in advance.
Solved! Go to Solution.
In the fLayer on click function, instead of instantiating a new genderChart, simply reuse the existing one (set up earlier in the script) by commenting out line 38
on(fLayer, 'click', function (e) {
//node.value = e.graphic.attributes.FEMALES;
var stateFnum, stateMnum, stateOwnerNum, stateRenterNum;
document.getElementById("popUSA").innerHTML = "Total Gender Population " + e.graphic.attributes.STATE_NAME;
document.getElementById("occupancyUSA").innerHTML = "Owner Versus Renter " + e.graphic.attributes.STATE_NAME;
document.getElementById("totalFemales").innerHTML = "Total Females: " + e.graphic.attributes.FEMALES.toLocaleString();
document.getElementById("totalMales").innerHTML = "Total Males: " + e.graphic.attributes.MALES.toLocaleString();
document.getElementById("totalOwners").innerHTML = "Total Homeowners: " + e.graphic.attributes.OWNER_OCC.toLocaleString();
document.getElementById("totalRenter").innerHTML = "Total Renters: " + e.graphic.attributes.RENTER_OCC.toLocaleString();
stateFnum = e.graphic.attributes.FEMALES;
stateMnum = e.graphic.attributes.MALES;
stateOwnerNum = e.graphic.attributes.OWNER_OCC;
stateRenterNum = e.graphic.attributes.RENTER_OCC;
document.getElementById("totalPop").innerHTML = "Total Population: " + (stateFnum + stateMnum).toLocaleString();
document.getElementById("totalOccupancy").innerHTML = "Total Occupancy: " + (stateOwnerNum + stateRenterNum).toLocaleString();;
map.on('click', executeClickQuery);
var queryTask5 = new Qt("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3");
var mySymbol = new SimpleFillSymbol("none",
new SimpleLineSymbol("solid", new dojo.Color([0, 255, 255]), 3.2), new dojo.Color([255, 255, 0, 0.25]));
var query = new Query();
query.returnGeometry = true;
function executeClickQuery(evt) {
query.geometry = evt.mapPoint;
queryTask5.execute(query, showResults);
}
function showResults(featureSet) {
map.graphics.clear();
dojo.forEach(featureSet.features, function (feature) {
var graphic = feature;
graphic.setSymbol(mySymbol);
map.graphics.add(graphic);
});
}
//console.log("No " + stateFnum + " " + stateMnum);
var genderTheme = new SimpleTheme({
colors: ["#8888ff", "#ff8888"]
})
//genderChart = new Chart("genderGraph");
//add in a customize theme
genderChart.setTheme(genderTheme).addPlot("default", {
type: Pie,
font: "normal normal 8pt Tahoma",
fontColor: "black",
radius: 60 //radius of 60 pixels
}).addSeries("Series A", [stateFnum, stateMnum]);
var amin_aa = new Tooltip(genderChart, "default");
var anim_bb = new Highlight(genderChart, "default");
genderChart.render();
});
In the fLayer on click function, instead of instantiating a new genderChart, simply reuse the existing one (set up earlier in the script) by commenting out line 38
on(fLayer, 'click', function (e) {
//node.value = e.graphic.attributes.FEMALES;
var stateFnum, stateMnum, stateOwnerNum, stateRenterNum;
document.getElementById("popUSA").innerHTML = "Total Gender Population " + e.graphic.attributes.STATE_NAME;
document.getElementById("occupancyUSA").innerHTML = "Owner Versus Renter " + e.graphic.attributes.STATE_NAME;
document.getElementById("totalFemales").innerHTML = "Total Females: " + e.graphic.attributes.FEMALES.toLocaleString();
document.getElementById("totalMales").innerHTML = "Total Males: " + e.graphic.attributes.MALES.toLocaleString();
document.getElementById("totalOwners").innerHTML = "Total Homeowners: " + e.graphic.attributes.OWNER_OCC.toLocaleString();
document.getElementById("totalRenter").innerHTML = "Total Renters: " + e.graphic.attributes.RENTER_OCC.toLocaleString();
stateFnum = e.graphic.attributes.FEMALES;
stateMnum = e.graphic.attributes.MALES;
stateOwnerNum = e.graphic.attributes.OWNER_OCC;
stateRenterNum = e.graphic.attributes.RENTER_OCC;
document.getElementById("totalPop").innerHTML = "Total Population: " + (stateFnum + stateMnum).toLocaleString();
document.getElementById("totalOccupancy").innerHTML = "Total Occupancy: " + (stateOwnerNum + stateRenterNum).toLocaleString();;
map.on('click', executeClickQuery);
var queryTask5 = new Qt("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3");
var mySymbol = new SimpleFillSymbol("none",
new SimpleLineSymbol("solid", new dojo.Color([0, 255, 255]), 3.2), new dojo.Color([255, 255, 0, 0.25]));
var query = new Query();
query.returnGeometry = true;
function executeClickQuery(evt) {
query.geometry = evt.mapPoint;
queryTask5.execute(query, showResults);
}
function showResults(featureSet) {
map.graphics.clear();
dojo.forEach(featureSet.features, function (feature) {
var graphic = feature;
graphic.setSymbol(mySymbol);
map.graphics.add(graphic);
});
}
//console.log("No " + stateFnum + " " + stateMnum);
var genderTheme = new SimpleTheme({
colors: ["#8888ff", "#ff8888"]
})
//genderChart = new Chart("genderGraph");
//add in a customize theme
genderChart.setTheme(genderTheme).addPlot("default", {
type: Pie,
font: "normal normal 8pt Tahoma",
fontColor: "black",
radius: 60 //radius of 60 pixels
}).addSeries("Series A", [stateFnum, stateMnum]);
var amin_aa = new Tooltip(genderChart, "default");
var anim_bb = new Highlight(genderChart, "default");
genderChart.render();
});
Well that does it!
Very simple, can't believe I missed it.
Thanks alot Ken.
By the way how are you able to get the code to format nicely with the line number and all?
Take a look at this blog. However, note that the Syntax Highlighter option does not appear when replying through the Inbox.