바를 클릭하면 차트 상단에있는 <span>
에 'isStacked : true'가있는 곳에 barchart의 합계 값을 표시하려고합니다.Google 시각화 -Click 이벤트를 barchart isStacked : true
Uncaught TypeError: Cannot read property 'row' of undefined
또는 내가 row
column
에 변경 때 나는이 오류를 받았습니다은 A 표시 줄을 클릭하면 google.visualization.events.addListener의 기능을 탐구하는
내 참조
here. 시작
Uncaught TypeError: Cannot read property 'column' of undefined
모든 포인터는 정말 감사하겠습니다.
<script type="text/javascript">
$(document).ready(function(){
{% for staff_name, staff_id in params.items %}
$.ajax({
url: "{% url user_kpi %}",
data: { user_stat: {{staff_name}} },
success: function(responseData) {
if (typeof responseData=="object") {
var data = new google.visualization.arrayToDataTable([
['Type', 'Processed Items', { role: 'style' }, 'Processed beyond Due Date', { role: 'style'}],
['PPP', responseData['PPP_ontime'], 'lightgreen', responseData['PPP_due'], 'red'],
['CP', responseData['CP_ontime'], 'gold', responseData['CP_due'], 'red'],
['RSL', responseData['RSL_ontime'], 'lightblue', responseData['RSL_due'], 'red'],
['MOD', responseData['MOD_ontime'], 'yellow', responseData['MOD_due'], 'red' ],
['STO', responseData['RECALL_ontime'], 'silver', responseData['RECALL_due'], 'red'],
['TP', responseData['TP_ontime'], 'orange', responseData['TP_due'], 'red'],
['DEMO', responseData['DEMO_ontime'], 'violet', responseData['DEMO_due'], 'red'],
['DUP', responseData['DUP_ontime'], 'brown', responseData['DUP_due'], 'red']]);
google.setOnLoadCallback(drawVisualization(data, {{staff_name}}));
}
}
});
{% endfor %}
});
var wrapper;
function drawVisualization(xdata, id) {
// Create and draw the visualization.
var visual = 'visualization-'+id.toString();
//chart = new google.visualization.BarChart(document.getElementById(visual));
wrapper = new google.visualization.ChartWrapper({
chartType: 'BarChart',
dataTable: xdata,
options: {
width:600, height:140,
vAxis: {title: null, maxValue: 3500},
hAxis: {title: null},
animation: {easing: 'in'},
axisTitlesPosition: "out",
chartArea:{left:0,top:0, right:0, width:"100%",height:"100%"},
focusTarget: "category",
fontSize: 12,
fontName: "Tahoma",
legend: {position: 'none'},
series: [{color: 'black', visibleInLegend: false}, {}, {},
{color: 'red', visibleInLegend: false}],
isStacked: true,
backgroundColor: '#eee',
},
containerId: visual
});
google.visualization.events.addListener(wrapper, 'ready', function() {
// grab a few details before redirecting
google.visualization.events.addListener(wrapper.getChart(), 'select', function() {
chartObject = wrapper.getChart();
// checking value upon mousehover
alert(xdata.getValue(chartObject.getSelection()[0].row, 0));
//alert(xdata.getValue(chartObject.getSelection()[0].column, 0));
});
});
wrapper.draw();
}
이
이 업데이트 :으로는 asgallant에 의해 설명
여기 내 장고 템플릿입니다.
<script type="text/javascript">
function init() {
{% for staff_name, staff_id in params.items %}
$.ajax({
url: "{% url user_kpi %}",
data: { user_stat: {{staff_name}} },
success: function(responseData) {
if (typeof responseData=="object") {
var data = new google.visualization.arrayToDataTable([
['Type', 'Processed Items', { role: 'style' }, 'Processed beyond Due Date', { role: 'style'}],
['PPP', responseData['PPP_ontime'], 'lightgreen', responseData['PPP_due'], 'red'],
['CP', responseData['CP_ontime'], 'gold', responseData['CP_due'], 'red'],
['RSL', responseData['RSL_ontime'], 'lightblue', responseData['RSL_due'], 'red'],
['MOD', responseData['MOD_ontime'], 'yellow', responseData['MOD_due'], 'red' ],
['STO', responseData['RECALL_ontime'], 'silver', responseData['RECALL_due'], 'red'],
['TP', responseData['TP_ontime'], 'orange', responseData['TP_due'], 'red'],
['DEMO', responseData['DEMO_ontime'], 'violet', responseData['DEMO_due'], 'red'],
['DUP', responseData['DUP_ontime'], 'brown', responseData['DUP_due'], 'red']
]);
drawVisualization(data, {{staff_name}});
}
}
});
{% endfor %}
}
google.load('visualization', '1', {packages:['corechart'], callback: init});
function drawVisualization(xdata, id) {
// Create and draw the visualization.
var visual = 'visualization-'+id.toString(),
//chart = new google.visualization.BarChart(document.getElementById(visual));
wrapper = new google.visualization.ChartWrapper({
chartType: 'BarChart',
dataTable: xdata,
options: {
width:600, height:140,
vAxis: {title: null, maxValue: 3500},
hAxis: {title: null},
animation: {easing: 'in'},
axisTitlesPosition: "out",
chartArea:{left:0,top:0, right:0, width:"100%",height:"100%"},
focusTarget: "category",
fontSize: 12,
fontName: "Tahoma",
legend: {position: 'none'},
//orientation: "vertical"
series: [{color: 'black', visibleInLegend: false}, {}, {},
{color: 'red', visibleInLegend: false}],
isStacked: true,
backgroundColor: '#eee',
},
containerId: visual
});
google.visualization.events.addListener(wrapper, 'ready', function() {
var chart = wrapper.getChart();
google.visualization.events.addListener(chart, 'select', function() {
var selection = chart.getSelection();
if (selection.length) {
// the user selected a bar
alert(xdata.getValue(selection[0].row, 0));
//alert(selection.length);
}
else {
alert('no selection');// the user deselected a bar
}
});
});
wrapper.draw();
}
오류 : catch되지 않은 오류 : 정의되지 않은 잘못된 행 인덱스입니다. [0-7] 범위 내에 있어야합니다. asgallant에 의해 Corrrected
이 가 alert(xdata.getValue(selection[0].row, 0));
에이 라인 alert(xdata.getValue(selection.row, 0));
켜기
아약스/js/jquery 내부의 것들이 어떻게 연결되는지 명확히 설명해 주셔서 감사합니다.나는 당신의 지시를 따랐고 나는 이벤트 선택 작업을하고있다. 나는 아직도 가치를 얻는 데 문제가있다. 위의 질문에 오류가있는 업데이트를 붙여 넣습니다. – Charlesliam
죄송합니다,'selection.row'는'selection [0] .row'이어야합니다. 내 대답을 업데이트 할게. – asgallant
그것은 PPP 나 CP와 같은 가치를 나에게주고 있습니다. 원래는 숫자 값을 줄 것이라고 생각했습니다. 여기에서 js 스크립트를 추가하여 실제 값을 얻을 수 있습니다. 애쓰는이 질문에 대해 생각해 보도록하겠습니다. – Charlesliam