Google Charts

19 views
Skip to first unread message

Wagner Lima Chimenez

unread,
Aug 29, 2017, 9:08:05 AM8/29/17
to Google Visualization API
Hi, everyone

I'm trying to dynamically call up to show many graphics on the same page, because I do not know how many graphics I need.
I need to create graphics at runtime. What is the problem with my code?

$(document).ready(function () {
    graph_curving_the_lines();
});

var graph_curving_the_lines = function () {

    var graficos = $('.graph_curving_the_lines');
    var params, self, id_grafico, nome_funcao;

    graficos.each(function () {

        self = $(this);

        id_grafico = self.attr('id');

        nome_funcao = 'funcao_' + id_grafico;

        params = self.data('params');

        if (typeof params != 'undefined') {

            console.log(nome_funcao);
            
            google.charts.load('current', {'packages': ['corechart']});
            google.charts.setOnLoadCallback(nome_funcao);
            
            window[nome_funcao] = function () {
                var data = google.visualization.arrayToDataTable(params.data);
                var options = params.options;
                var chart = new google.visualization.LineChart(document.getElementById('' + id_grafico));

                chart.draw(data, options);
            };

        }

    });

};
Reply all
Reply to author
Forward
0 new messages