I am trying to add a sparkline chart at the end of each row of my dynamically populated table. Here is my code:
function populateOverallOverview(result){
var table = document.getElementById("firstTabOverall");
function addCell(tr, text) {
var td = tr.insertCell();
td.textContent = text;
return td;
}
result.forEach(function (item) {
// sparkline chart here
var dataSpan = document.createElement('span');
dataSpan.sparkline(amountData, {
type: 'bar',
barColor: '#191919'});
var row = table.insertRow();
addCell(row, item.category);
addCell(row, '$ ' + item.currentMonthAmt.toFixed(2));
addCell(row, item.topMonthStr + ' ($ ' + item.topAmount.toFixed(2) + ')');
});
}
Sample data for the amountData are [5,6,7,2,0,-4,-2,4]. My HTML table:
<table id="firstTabOverall" class="table" style="font-size:13px">
<tr>
<th>Category <span id="sparkline1"></span></th>
<th>Current Month Revenue</th>
<th>Best Selling Month</th>
</tr>
</table>
I am trying to dynamically create the sparkline chart then add to the end of the row. However, I am getting this error message:
Uncaught (in promise) TypeError: dataSpan.sparkline is not a function
I not sure how to dynamically create a span with ID, then use that ID to .sparkline. Any ideas?