Here is the specific table I am working with:
<div class="chartHeader"><p>Performance statistics summary</p></div>
<table id="tableSummary">
<tr>
<th>Measurement name</th>
<th>Result</th>
</tr>
<tr>
<td>Total messages sent</td>
<td id = "totalMessagesSent"></td>
</tr>
<tr>
<td>Total messages processed</td>
<td id = "totalMessagesProcessed"></td>
</tr>
<tr>
<td>Average messages per second</td>
<td id = "averageMessagesPerSecond"></td>
</tr>
</table>
I have a JSON file generated in Groovy stored somewhere on my disk:
{
"reportSummary": {
"totalMessagesSent": 23,
"totalMessagesProcessed": 10384,
"averageMessagesPerSecond": 2.3E-8
}
}
I've been trying to populate the table above with data from this JSON using JavaScript, but so far I haven't been successful. In my HTML page, I have added:
<script type="text/javascript">fillTableWithData('reportSummary.json');</script>
Currently, my script looks like this, but it's not functioning as intended:
function fillTableWithData(filename) {
var reader = new FileReader();
var jsonFile = reader.readAsText(filename);
var jsons = d3.json(jsonFile);
d3.select("#totalMessagesSent").append(jsons.totalMessagesSent);
d3.select("#totalMessagesProcessed").append(jsons.totalMessagesProcessed);
d3.select("#averageMessagesPerSecond").append(jsons.averageMessagesPerSecond);
}
If anyone has suggestions on how to correctly achieve this task, please let me know. I've spent a lot of time on it and I'm currently out of ideas. Thank you in advance for your help.
EDIT: If it's easier to do it in pure JS, I don't necessarily need to use d3 for this task...