1
我有一個用正確的數據正確地顯示這個餅圖:chart.js之CoffeeScript中無法找到變量
# setup the pieChart
if ($("#pieChart").length)
poll_labels = []
poll_data = []
poll_colors = []
$('.option_text').each (i, obj) ->
poll_labels.push($(obj).text())
return
$('.nb_votes').each (i, obj) ->
poll_data.push($(obj).text())
poll_colors.push('#' + Math.floor(Math.random() * 16777215).toString(16))
return
data =
labels: poll_labels
datasets: [ {
data: poll_data
backgroundColor: poll_colors
hoverBackgroundColor: poll_colors
} ]
ctx = document.getElementById('pieChart')
pollPieChart = new Chart(ctx,
type: 'pie'
data: data
animation: animateRotate:true)
$('#pieChart').on 'data:update', (event, data_id, data) ->
$('.answer_option').each (i, obj) ->
if($(obj).attr('id') == ("option_" + data_id))
this.pollPieChart.data.datasets[0].data[i] = data
this.pollPieChart.update()
然而,data:update
事件找不到pollPieChart變量更新呢? 這不是在window.pollPieChart
,我只是在pollPieChart
找不到它。新變量之後變量是否「消失」?
嗯,我可以發誓,我嘗試過通過自身pollPieChart發佈此之前。但它現在起作用。謝謝! – AntoineLev