I'm a very new user of Javascript and data files. I am building a webpage that uses charts built with Chart.js to display character data from an .xml file exported from a creative writing program. The original xml file structure had all the data stored in attributes, so I've redesigned it so that it is in elements instead.
My aim is to draw and count data from this file and display it in a chart. For example, to draw the number of females and males from the gender element in my .xml file and display that in a chart. How would I do that using Javascript? I already have the webpage part-built and functioning with the data hard-coded into the JS, but that isn't suitable as I need to link it to the program I'm working with.
HTML:
<center><h4>Genders</h4>
<canvas id="genderchart" width="250px" height="250px"></canvas></center>
JS for above chart:
var ctx = document.getElementById("genderchart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ["NB ", "M ", "F "],
datasets: [{
backgroundColor: [
"#FFEB3B",
"#3F51B5",
"#E91E63"
],
data: [1, 16, 13]
}]
},
options: {
legend: {
display: true,
labels: {
boxWidth: 13,
}
},
}
});
The .xml file is extremely long because it contains data other than gender, but this is the basic structure of the section I'd like to input:
<characterInfoList>
<harryPotter>
<gender>male</gender>
</harryPotter>
<ronWeasley>
<gender>male</gender>
</ronWeasley>
<hermioneGranger>
<gender>female</gender>
</hermioneGranger>
<lordVoldemort>
<gender>male</gender>
</lordVoldemort>
<albusDumbledore>
<gender>male</gender>
</albusDumbledore>
<severusSnape>
<gender>male</gender>
</severusSnape>
</characterInfoList>
Can anyone help? This is my first time posting here but I've gotten so much help from the questions of others' posted before me. I'm really sorry if this question is super basic but I'm just finding it so difficult.