Google maps and Google charts on the same page

85 views
Skip to first unread message

Tranquilo DF

unread,
Feb 21, 2017, 6:55:38 PM2/21/17
to Google Visualization API
English on the botton.

Pessoal,

Estou tentando colocar na mesma página 2 gráficos e 1 Mapa, como posso executar?

Abaixo, segue o código:

<script type="text/javascript">

    // Load the Visualization API and the piechart package.
    //google.load('visualization', '1.0', {'packages':['corechart']});
    google.charts.load('current', {'packages':['corechart']});
    //google.charts.load('upcoming', { 'packages': ['map'] });


    // Set a callback to run when the Google Visualization API is loaded.
    //google.setOnLoadCallback(drawChart);
    google.charts.setOnLoadCallback(drawChart);

    // Callback that creates and populates a data table,
    // instantiates the pie chart, passes in the data and
    // draws it.
    function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Status');
        data.addColumn('number', 'Qtd');
        data.addRows([
            ['Aguardando Início', 6],
            ['Em andamento', 11],
            ['Concluídas', 8],
            ['Canceladas', 2]

        ]);

        // Set chart options
        var options = {
            title:'Status das Viagens - Mês',
            colors: ['#1c91c0', '#f1ca3a', '#6f9654', '#e0440e'],
            titleTextStyle: {
                fontSize:18,
                fontName: 'Lato'
            },
            chartArea:{
                left:50,
                top:30,
                width:'65%',
                height:'75%'
            },
            legend: { alignment:'center' },
            pieHole: 0.4
            //,is3D: true
            //,width:100
            //,height:300
        };

        // Create the data table.
        var data2 = new google.visualization.DataTable();
        data2.addColumn('string', 'Status');
        data2.addColumn('number', 'Abertura');
        data2.addColumn('number', 'Em andamento');
        data2.addColumn('number', 'Conclusão');
        data2.addColumn('number', 'Cancelamento');
        data2.addRows([
            ['28/01', 8, 4, 6, 9],
            ['29/01', 5, 8, 1, 6],
            ['30/01', 10, 3, 7, 20],
            ['31/01', 7, 2, 8, 11]
        ]);

        // Set chart options
        var options2 = {
            title:'Viagens diárias por status',
            colors: ['#1c91c0', '#f1ca3a', '#6f9654', '#e0440e'],
            titleTextStyle: {
                fontSize:18,
                fontName: 'Lato'
            },
            vAxes: {
                // Adds titles to each axis.
                0: {title: 'Qtde. Viagens',
                    minValue: 0
                }
            },
            chartArea:{
                left:50,
                top:30,
                width:'65%',
                height:'75%'
            },
            legend: { alignment:'center' }
        };

        var data3 = google.visualization.arrayToDataTable([
            ['Lat', 'Long', 'Local'],
            [-21.3809029, -47.7045149, 'Local 1'],
            [-23.1520142, -46.9393065, 'Local 2'],
            [-23.0524649, -47.0494738, 'Local 3']
        ]);

        var options3 = {
            title:'Localização',
            showTooltip: true,
            showInfoWindow: true
        };

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
        var chart2 = new google.visualization.LineChart(document.getElementById('chart_div2'));
        chart2.draw(data2, options2);
        var chart3 = new google.visualization.Map(document.getElementById('chart_div3'));
        chart3.draw(data3, options3);
    }

    $(window).resize(function(){
        drawChart();
    });
</script>


<div class="container">
    <div class="row">
        <section>
            <form role="form">
                <div class="row mar_ned col-md-12 col-xs-12 col-sm-12 col-lg-12">
                    <p>Bem vindo ao sistema de gestão de produtos Ciltronics!</p>

                    <hr>

                    <div class="row mar_ned">

                    </div>

                    <div class="row mar_ned col-sm-12 col-md-12 col-lg-12 col-xs-12 ">
                        <div class="col-sm-6 col-md-6 col-lg-6">
                            <div id="chart_div" style="width: 100%; max-width: 550px; min-height: 250px; border: 1px outset #cfcfcf;"></div>
                        </div>

                        <div class="col-sm-6 col-md-6 col-lg-6">
                            <div id="chart_div2" style="width: 100%; max-width: 550px; min-height: 250px; border: 1px outset #cfcfcf;"></div>
                        </div>
                    </div>

                    <div class="row mar_ned col-sm-12 col-md-12 col-lg-12 col-xs-12 ">
                        <div class="col-sm-12 col-md-12 col-lg-12">
                            <div id="chart_div3" style="width: 100%; max-width: 550px; min-height: 250px; border: 1px outset #cfcfcf;"></div>
                        </div>
                    </div>

                    <div class="row mar_ned">

                    </div>

                </div>
            </form>
        </section>
    </div>
</div>

Desde já agradeço a ajuda.

-

Folks,

I'm trying to put on the same page 2 charts and 1 Map, how can I execute?

Below is the code:

<script type="text/javascript">

    // Load the Visualization API and the piechart package.
    //google.load('visualization', '1.0', {'packages':['corechart']});
    google.charts.load('current', {'packages':['corechart']});
    //google.charts.load('upcoming', { 'packages': ['map'] });


    // Set a callback to run when the Google Visualization API is loaded.
    //google.setOnLoadCallback(drawChart);
    google.charts.setOnLoadCallback(drawChart);

    // Callback that creates and populates a data table,
    // instantiates the pie chart, passes in the data and
    // draws it.
    function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Status');
        data.addColumn('number', 'Qtd');
        data.addRows([
            ['Aguardando Início', 6],
            ['Em andamento', 11],
            ['Concluídas', 8],
            ['Canceladas', 2]

        ]);

        // Set chart options
        var options = {
            title:'Status das Viagens - Mês',
            colors: ['#1c91c0', '#f1ca3a', '#6f9654', '#e0440e'],
            titleTextStyle: {
                fontSize:18,
                fontName: 'Lato'
            },
            chartArea:{
                left:50,
                top:30,
                width:'65%',
                height:'75%'
            },
            legend: { alignment:'center' },
            pieHole: 0.4
            //,is3D: true
            //,width:100
            //,height:300
        };

        // Create the data table.
        var data2 = new google.visualization.DataTable();
        data2.addColumn('string', 'Status');
        data2.addColumn('number', 'Abertura');
        data2.addColumn('number', 'Em andamento');
        data2.addColumn('number', 'Conclusão');
        data2.addColumn('number', 'Cancelamento');
        data2.addRows([
            ['28/01', 8, 4, 6, 9],
            ['29/01', 5, 8, 1, 6],
            ['30/01', 10, 3, 7, 20],
            ['31/01', 7, 2, 8, 11]
        ]);

        // Set chart options
        var options2 = {
            title:'Viagens diárias por status',
            colors: ['#1c91c0', '#f1ca3a', '#6f9654', '#e0440e'],
            titleTextStyle: {
                fontSize:18,
                fontName: 'Lato'
            },
            vAxes: {
                // Adds titles to each axis.
                0: {title: 'Qtde. Viagens',
                    minValue: 0
                }
            },
            chartArea:{
                left:50,
                top:30,
                width:'65%',
                height:'75%'
            },
            legend: { alignment:'center' }
        };

        var data3 = google.visualization.arrayToDataTable([
            ['Lat', 'Long', 'Local'],
            [-21.3809029, -47.7045149, 'Local 1'],
            [-23.1520142, -46.9393065, 'Local 2'],
            [-23.0524649, -47.0494738, 'Local 3']
        ]);

        var options3 = {
            title:'Localização',
            showTooltip: true,
            showInfoWindow: true
        };

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
        var chart2 = new google.visualization.LineChart(document.getElementById('chart_div2'));
        chart2.draw(data2, options2);
        var chart3 = new google.visualization.Map(document.getElementById('chart_div3'));
        chart3.draw(data3, options3);
    }

    $(window).resize(function(){
        drawChart();
    });
</script>


<div class="container">
    <div class="row">
        <section>
            <form role="form">
                <div class="row mar_ned col-md-12 col-xs-12 col-sm-12 col-lg-12">
                    <p>Bem vindo ao sistema de gestão de produtos Ciltronics!</p>

                    <hr>

                    <div class="row mar_ned">

                    </div>

                    <div class="row mar_ned col-sm-12 col-md-12 col-lg-12 col-xs-12 ">
                        <div class="col-sm-6 col-md-6 col-lg-6">
                            <div id="chart_div" style="width: 100%; max-width: 550px; min-height: 250px; border: 1px outset #cfcfcf;"></div>
                        </div>

                        <div class="col-sm-6 col-md-6 col-lg-6">
                            <div id="chart_div2" style="width: 100%; max-width: 550px; min-height: 250px; border: 1px outset #cfcfcf;"></div>
                        </div>
                    </div>

                    <div class="row mar_ned col-sm-12 col-md-12 col-lg-12 col-xs-12 ">
                        <div class="col-sm-12 col-md-12 col-lg-12">
                            <div id="chart_div3" style="width: 100%; max-width: 550px; min-height: 250px; border: 1px outset #cfcfcf;"></div>
                        </div>
                    </div>

                    <div class="row mar_ned">

                    </div>

                </div>
            </form>
        </section>
    </div>
</div>

tks to help

Att,

Lindolfo Junior
61 9 99771425

Daniel LaLiberte

unread,
Feb 22, 2017, 8:39:23 AM2/22/17
to Google Visualization API
Hi Lindolfo,

You need to load the 'map' package in addition to 'corechart'.

  google.charts.load('current', { 'packages': ['corechart', 'map'] });

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/6571b0ea-55f9-4846-849e-87b7ead7f362%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA

Tranquilo DF

unread,
Feb 22, 2017, 8:07:07 PM2/22/17
to Google Visualization API
Hi Daniel,

Thank you for help! 
Now it's working, but when i try to use icons it's crash and dont show nothing... What can be?

var options3 = {
   
showTooltip: true,
    showInfoWindow: true,
    useMapTypeControl: true,
    icons: {
       
blue: {
           
normal:   url + 'Map-Marker-Marker-Outside-Azure-icon.png',
            selected: url + 'map-marker-icon.png'
        },
        green: {
           
normal:   url + 'Map-Marker-Push-Pin-1-Chartreuse-icon.png',
            selected: url + 'Map-Marker-Push-Pin-1-Right-Chartreuse-icon.png'
        },
        pink: {
           
normal:   url + 'Map-Marker-Ball-Pink-icon.png',
            selected: url + 'Map-Marker-Ball-Right-Pink-icon.png'
        }
};



Att,

Lindolfo Junior

To post to this group, send email to google-visua...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA

Tranquilo DF

unread,
Feb 23, 2017, 8:31:03 AM2/23/17
to Google Visualization API
The complete code is:

var data3 = google.visualization.arrayToDataTable([
            ['Lat',         'Long',         'Local',    'Marker'],
            [-21.3809029,   -47.7045149,    'Viagem 1', 'red'],
            [-23.1520142,   -46.9393065,    'Viagem 2', 'green'],
            [-23.0524649,   -47.0494738,    'Viagem 3', 'blue']
        ]);


        var options3 = {
            showTooltip: true,
            showInfoWindow: true,
            useMapTypeControl: true,
            icons: {
                blue: {
                    normal:   url + 'Map-Marker-Marker-Outside-Azure-icon.png',
                    selected: url + 'map-marker-icon.png'
                },
                green: {
                    normal:   url + 'Map-Marker-Push-Pin-1-Chartreuse-icon.png',
                    selected: url + 'Map-Marker-Push-Pin-1-Right-Chartreuse-icon.png'
                },
                pink: {
                    normal:   url + 'Map-Marker-Ball-Pink-icon.png',
                    selected: url + 'Map-Marker-Ball-Right-Pink-icon.png'
                }
        };

Tranquilo DF

unread,
Feb 27, 2017, 3:06:21 PM2/27/17
to Google Visualization API
Someone knows what can be done?
Reply all
Reply to author
Forward
0 new messages