Google Chart:如何在饼图中添加select事件处理程序?

时间:2016-09-01 04:07:01

标签: google-visualization

我能够成功生成饼图。但是,当我尝试将一个select事件侦听器添加到饼图时,它根本不会触发该函数。

function handlePieChartResponse(response)
    {
        if (response.isError()) {
            alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
            return;
        }
        var dataTable = response.getDataTable();
        if (dataTable.getNumberOfRows() <= 0) {
            document.getElementById('dummyTableRow').innerHTML = '<span>No data found</span>';
            return;
        }

        var chartOptions = DEFAULT_PIE_CHART_OPTIONS;
        //var chartOverallPmmLevelCalculated = new google.visualization.ChartWrapper({
           // 'chartType': 'PieChart',
           // 'containerId': 'chartOverallPmmLevelCalculatedHtml',
            // options: chartOptions
        //});

        var chartRecentPmmLevelCalculated = new google.visualization.PieChart(document.getElementById('chartOverallPmmLevelCalculatedHtml'));
        chartRecentPmmLevelCalculated.draw(dataTable, chartOptions);

        google.visualization.events.addListener(chartRecentPmmLevelCalculated, 'ready', function () { drawPieChart(); });
        google.visualization.events.addListener(chartRecentPmmLevelCalculated, 'select', function () { selectHandler(); });

        function drawPieChart() {
            var responseDataTable = response.getDataTable();
            var chartDataTable = new google.visualization.DataTable();
            chartDataTable.addColumn('string', 'LEVEL');
            chartDataTable.addColumn('number', 'SCORE');
            var chartDataTableRow = new Array();
            var rowCounter;
            var levelValue;
            for (rowCounter = 0; rowCounter < responseDataTable.getNumberOfRows() ; rowCounter++) {
                var seek = 0 * 1;
                levelValue = responseDataTable.getValue(rowCounter, 0);
                chartDataTableRow[seek++] = "LEVEL " + levelValue;
                chartDataTableRow[seek++] = responseDataTable.getValue(rowCounter, 1);
                chartDataTable.addRow(chartDataTableRow);
            }
            chartDataTable.sort([{ column: 1 }]);
            chartOverallPmmLevelCalculated.setDataTable(chartDataTable);
            chartOverallPmmLevelCalculated.draw();
        }
        handlePieChartResponse.drawPieChart = drawPieChart;
    }

    function selectHandler() {
        alert("This alert triggered from pie chart");
        var selectedItem = chartRecentPmmLevelCalculated.getSelection();
        if (selectedItem) {
            var levelSelected = chartOverallPmmLevelCalculated.getValue(selectedItem.row, 0);
            alert(levelSelected);
        }
    }

我附加了包含点击前后的2张图片。一旦在饼图切片上选择,我期待警报消息。但是没有警报,并且未触发函数调用。

Before Click After Click on the slice

1 个答案:

答案 0 :(得分:2)

问题与范围

有关

from gensim.models import word2vec model = Word2Vec.load_word2vec_format(doc_set, binary=False) 不在函数selectHandler

之内

所以无法找到

只需将其移至handlePieChartResponse

然后设置事件,就像这样......

handlePieChartResponse