barchart.sparkline is not a function

59 views
Skip to first unread message

Shamir omy

unread,
Feb 9, 2020, 7:42:32 AM2/9/20
to jQuery Sparkline
I was going throw the title from FAQ "How do I draw a sparkline on an element that is not yet in the DOM?"
Basically I am getting data from ajax call and trying to create a table with sparkline bar inside table row. I am getting an error when sparkline function call. Basically it happen when I append in DOM. If span already in DOM it's work fine. 
* I have checked by debugger jQuery and sparkline library loading correctly before my code run. My code is here -
function createTable(tob){
for (var [module, focusDetails] of Object.entries(tob)) {
//console.log(module);
var focusList = focusDetails.focusDetails;
console.log(focusList);
var divColumn = $('<div>').addClass('column');
let divCard = $('<div>').addClass('card');
let table = $('<table>').addClass('table table-striped');
let thead = $('<thead>').addClass('thead');
let trtitle = $('<tr>');
let title = $('<b>').text(module);
trtitle.append(title);
thead.append(trtitle);
let trHead = $('<tr>');
let headRow = '<th></th><th>Tdy</th><th>Yda</th><th> % +/-</th><th>7 Days</th><th>Top Depts</th>';
trHead.append(headRow);
thead.append(trHead);
table.append(thead);
let tbody = $('<tbody>').addClass('tbody');
for (var [focusName, focusRow] of Object.entries(focusList)) {
let row = $('<tr>');
let tdFocusName = $('<td>').text(focusName);
let tdCountTday = $('<td>').text(focusRow.count_tdy);
let tdCountYday = $('<td>').text(focusRow.count_ydy);
let tdChart = $('<td>');

                                                                let barchart = $('<span>&nbsp;</span>');
barchart.sparkline([1,2,3,2], {type: 'bar'});
//barchart.sparkline(focusRow.last7days, {type: 'bar'});

tdChart.append(barchart);
let tdLocation = $('<td>').text(focusRow.location_tdy);
row.append(tdFocusName);
row.append(tdCountTday);
row.append(tdCountYday);
row.append(tdChart);
row.append(tdLocation);
tbody.append(row);
}
table.append(tbody);
divCard.append(table);
divColumn.append(divCard);
$("#chart-row").append(divColumn);
$.sparkline_display_visible();
}
}

I don't know where going wrong. Please Suggestion anyone.

Reply all
Reply to author
Forward
0 new messages