사용자가 선형 차트 범례를 클릭 할 때 선형 차트에서 선을 숨기려고합니다. Google Chart API에서 할 수있는 방법이 있습니까? Highcharts에서이 기능을 보았습니다.Google Line Chart 범례 Click 이벤트
3
A
답변
2
예 가능합니다. Here is an example by asgallant :
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'City');
data.addColumn('number', 'Foo');
data.addColumn('number', 'Foo');
data.addColumn('number', 'Bar');
data.addColumn('number', 'Bar');
data.addColumn('number', 'Baz');
data.addColumn('number', 'Baz');
data.addRow(['Boston', 5, null, 7, null, 2, null]);
data.addRow(['New York', 4, null, 8, null, 5, null]);
data.addRow(['Baltimore', 6, null, 2, null, 4, null]);
/* define the series object
* follows the standard 'series' option parameters, except it has two additonal parameters:
* hidden: true if the column is currently hidden
* altColor: changes the color of the legend entry (used to grey out hidden entries)
*/
var series = {
0: {
hidden: false,
visibleInLegend: false,
color: '#FF0000'
},
1: {
hidden: false,
color: '#FF0000',
altColor: '#808080'
},
2: {
hidden: false,
visibleInLegend: false,
color: '#00FF00'
},
3: {
hidden: false,
color: '#00FF00',
altColor: '#808080'
},
4: {
hidden: false,
visibleInLegend: false,
color: '#0000FF'
},
5: {
hidden: false,
color: '#0000FF',
altColor: '#808080'
}
};
var options = {
series: series,
height: 400,
width: 600
};
var view = new google.visualization.DataView(data);
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
google.visualization.events.addListener(chart, 'select', function() {
// if row is undefined, we clicked on the legend
if (typeof chart.getSelection()[0]['row'] === 'undefined') {
// column is the DataView column, not DataTable column
// so translate and subtract 1 to get the series index
var col = view.getTableColumnIndex(chart.getSelection()[0]['column']) - 1;
// toggle the selected column's data counterpart visibility
series[col - 1].hidden = !series[col - 1].hidden;
// swap colors
var tmpColor = series[col].color;
series[col].color = series[col].altColor;
series[col].altColor = tmpColor;
// reset the view's columns
view.setColumns([0,1,2,3,4,5,6]);
// build list of hidden columns and series options
var hiddenCols = [];
options.series = [];
for (var i = 0; i < 6; i++) {
if (series[i].hidden) {
// add 1 to the series index to get DataTable column
hiddenCols.push(i + 1);
}
else {
options.series.push(series[i]);
}
}
// hide the columns and draw the chart
view.hideColumns(hiddenCols);
chart.draw(view, options);
}
});
chart.draw(view, options);
}
1
여기 해결책이 있습니다. 범례를 클릭하여 선형 차트에서 선을 숨길 수 있습니다.
google.visualization.events.addListener(chart, 'select', function() {
var sel = chart.getSelection();
// if selection length is 0, we deselected an element
if (sel.length > 0) {
// if row is undefined, we clicked on the legend
if (typeof sel[0].row === 'undefined') {
var col = sel[0].column;
if (columns[col] == col) {
// hide the data series
columns[col] = {
label: data.getColumnLabel(col),
type: data.getColumnType(col),
calc: function() {
return null;
}
};
// grey out the legend entry
series[col - 1].color = '#CCCCCC';
}
else {
// show the data series
columns[col] = col;
series[col - 1].color = null;
}
var view = new google.visualization.DataView(data);
view.setColumns(columns);
chart.draw(view, options);
}
}
});
다음은 작동 샘플입니다. jqfaq.com
0
위에서 언급 한 바와 같이,
view.setColumns (chart.getSelection() [0] .column)를 호출, 당신은 당신의 DataTable에 대한 DataView를을 만든 다음만 클릭 한 행/열을 표시
는 클릭 한 행/열 호출 view.hideColumns (chart.getSelection() [0] .column)
대해 getSelection() 사용자가 선택한 차트에 선/전설이있을 것이다을 숨 깁니다.
관련 문제
- 1. Google Line Chart 시작 좌표?
- 2. Google Line Chart 단일 값
- 3. Highcharts Line Chart 시간주기
- 4. JFreeChart - Vertical Line Chart
- 5. XlsxWriter Column-Line Chart
- 6. JSON에서 D3 Multiseries Line Chart
- 7. Google Chart API의 문제 : 막대 차트 범례 텍스트 중복
- 8. Google Line Chart : 색상에 할당 된 변수 이름 목록을 비활성화하십시오.
- 9. Google Chart Dashboard Control 이벤트 처리기
- 10. Click 이벤트
- 11. Google Line Chart의 범례 클릭에 나타나는 줄 사용 안 함
- 12. AngularJS Google Chart : ChartRangeFilter
- 13. Ext JS Chart 범례 항목 맞춤
- 14. Extjs Line Chart 여러 줄 레이블
- 15. Phonegap + jQuery Mobile + Stock/Line Chart
- 16. Android TeeChart Line Chart 터치 감도
- 17. C# Line Chart 세로줄을 만드는 방법
- 18. google maps에서 click 및 closeclick 이벤트
- 19. Click 이벤트
- 20. Click 이벤트
- 21. Click 이벤트
- 22. Click on Click 이벤트 최적화하기
- 23. 방패 UI의 이벤트 차트 범례
- 24. google-Chart-API
- 25. Google Chart Tools
- 26. json repsonse google pie chart
- 27. Google Chart From PHP 변수
- 28. asp.net chart Onclick 이벤트 핸들러
- 29. Google 차트에서 범례 숨기기
- 30. Google 차트에 범례 추가
대시 보드 객체를 사용하면 어떻습니까? –
@Rutger, thankfully [asgallant] (http://stackoverflow.com/users/613559/asgallant)는 항상 여기에 참여합니다. 원래는 그의 논리이므로 새로운 질문을하는 것이 유용 할 수 있습니다. 하나, 그는 아마도 똑똑하고 너희들을 도우려고하기 때문에 대답 할 것입니다! – jmac