선택을 설정하는 경우 선택한 개체의 "열"매개 변수가 DataTable의 올바른 열을 참조하는지 확인하십시오.
편집 : 바 선택 효과를 보여 너무 작은 경우
, 당신은 대신에 선택에 바 색상을 변경하려면이 http://jsfiddle.net/asgallant/5SX8w/ 같은 해킹을 사용할 수 있습니다. 이것은 일련의 데이터 만 가지고있을 때 가장 효과적입니다. 시리즈가 두 개 이상인 경우 수정이 필요하며 누적 막대를 사용하지 않으면 제대로 표시되지 않을 수 있습니다.
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Value');
data.addRows([
['Foo', 94],
['Bar', 23],
['Baz', 80],
['Bat', 47],
['Cad', 32],
['Qud', 54]
]);
var chart = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
dataTable: data,
options: {
// setting the "isStacked" option to true fixes the spacing problem
isStacked: true,
height: 300,
width: 600,
series: {
1: {
// set the color to change to
color: '00A0D0',
// don't show this in the legend
visibleInLegend: false
}
}
}
});
google.visualization.events.addListener(chart, 'select', function() {
var selection = chart.getChart().getSelection();
if (selection.length > 0) {
var newSelection = [];
// if row is undefined, we selected the entire series
// otherwise, just a single element
if (typeof(selection[0].row) == 'undefined') {
newSelection.push({
column: 2
});
chart.setView({
columns: [0, {
type: 'number',
label: data.getColumnLabel(1),
calc: function() {
// this series is just a placeholder
return 0;
}
}, 1]
});
}
else {
var rows = [];
for (var i = 0; i < selection.length; i++) {
rows.push(selection[i].row);
// move the selected elements to column 2
newSelection.push({
row: selection[i].row,
column: 2
});
}
// set the view to remove the selected elements from the first series and add them to the second series
chart.setView({
columns: [0, {
type: 'number',
label: data.getColumnLabel(1),
calc: function (dt, row) {
return (rows.indexOf(row) >= 0) ? null : {v: dt.getValue(row, 1), f: dt.getFormattedValue(row, 1)};
}
}, {
type: 'number',
label: data.getColumnLabel(1),
calc: function (dt, row) {
return (rows.indexOf(row) >= 0) ? {v: dt.getValue(row, 1), f: dt.getFormattedValue(row, 1)} : null;
}
}]
});
}
// re-set the selection when the chart is done drawing
var runOnce = google.visualization.events.addListener(chart, 'ready', function() {
google.visualization.events.removeListener(runOnce);
chart.getChart().setSelection(newSelection);
});
}
else {
// if nothing is selected, clear the view to draw the base chart
chart.setView();
}
chart.draw();
});
chart.draw();
}
이 문제가 setSelection 기능을 취소하는 차트의 바가 너무 많으면 좋지 않을까요? 그것은 10-20 막대로 잘 작동하는 것처럼 보입니다.하지만 우리가하는 것처럼 많은 데이터를 가지고있을 때 - 마른 데이터 막대가 강조 표시되지 않습니다. jsfiddle- 제발 동의합니까? – Paul
예, 막대가 좁 으면 선택 영역에 시각적 효과가 나타나지 않습니다. – asgallant
당신이 알고있는 것을 해킹 할 수있는 방법이 있습니까? 이상적이지 않아. – Paul