remyremy
remyremy

Reputation: 3758

hideColumns and getVIewColumns with Google Charts

I'm trying to show/hide columns in a columnChart but things don't work as expected.

This is my chart (which works fine):

function drawGraph() {
        $.ajax({        
            type: "POST",
            url: "./functions.php",
                data: { action: 'draw_bar_chart'
            },
            dataType: 'json',
            success: function(jsonData) {
                data_chart = new google.visualization.DataTable(jsonData[0]['data']);
                var options = jsonData[1]['options'];

                // Instantiate and draw the chart
                chartColumn = new google.visualization.ColumnChart(document.getElementById('chart_div')); 
                data_chart.getViewColumns();
                chartColumn.draw(data_chart, options);
            }
        });
    } 

However, getViewColumns returns data_chart.getViewColumns is not a function

And here is how I intend to hide the button after I've got working getViewColumns

$('.toggle_button').click(function () {
            data_chart.hideColumns([1]); // To be adjusted
            chart.draw(data_chart, options);
        }
    );

Upvotes: 1

Views: 64

Answers (1)

WhiteHat
WhiteHat

Reputation: 61212

both of the following methods are members of the DataView Class...

getViewColumns()
hideColumns(columnIndexes)

and do not exist on the DataTable Class...

to correct, you could convert the data table to a data view...

data_chart = new google.visualization.DataTable(jsonData[0]['data']);

// convert data table to data view
data_chart = new google.visualization.DataView(data_chart);

var options = jsonData[1]['options'];

// Instantiate and draw the chart
chartColumn = new google.visualization.ColumnChart(document.getElementById('chart_div'));
data_chart.getViewColumns();
chartColumn.draw(data_chart, options);

Upvotes: 1

Related Questions