動的に取り込まれたテーブルの各行の最後にsparkline chartを追加しようとしています。ここに私のコードは次のとおりです。amountDataためダイナミックにポピュレートされたHTMLテーブルにスパークラインチャートを追加する
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) + ')');
});
}
サンプルデータ[5,6,7,2,0、-4、-2,4]です。私のHTMLテーブル:
<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>
スパークラインチャートを動的に作成して行の最後に追加しようとしています。しかし、このエラーメッセージが表示されています:
Uncaught (in promise) TypeError: dataSpan.sparkline is not a function
IDを持つスパンを動的に作成する方法がわかりません。そのIDを.sparklineに使用します。何か案は?
あなたは 'result'、あなたが出力するHTMLのために同じデータを追加することができます。 –
@BrahmaDevこんにちは私は質問を編集しました! – hyperfkcb