ALI ALRIKABI
ALI ALRIKABI

Reputation: 3

display google chart and gauge on the same web page

i am trying to load pie chart and gauge on the same web page. when i open the web page it only shows the 3 gauges and it's not displaying the pie chart. i have added corechart and gauge into one loader as recommended by google.

    <html>
   <head>

    <script type="text/javascript" 
    src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">

       google.charts.load('current', { packages: ['corechart', 'gauge'] });
       google.charts.setOnLoadCallback(drawChartb);
       google.charts.setOnLoadCallback(drawChart);

        function drawChartb() {

            var data = google.visualization.arrayToDataTable([
                ['Label', 'Value'],
                ['Port 1', 70],
                ['Port 2', 70],
                ['Port 3', 70]
            ]);

            var options = {
                width: 400, height: 120,
                redFrom: 90, redTo: 100,
                yellowFrom:75, yellowTo: 90,
                minorTicks: 5
            };
            var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
            chart.draw(data, options);
            setInterval(function() {
                data.setValue(0, 1, window.Power_chart1.Port1P);
                data.setValue(1, 1, window.Power_chart1.Port2P);
                data.setValue(2, 1, window.Power_chart1.Port3P);
                chart.draw(data, options);
            }, 1000);
        }
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
                ['Task', 'Hours per Day'],
                ['Port 1',     10],
                ['Port 2',      10],
                ['Port 3',  10]
            ]);

            var options = {
                title: 'Pie Chart Input Ports',
                pieHole: 0.4,
            };

            var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
            chart.draw(data, options);
            setInterval(function() {
                data.setValue(2, 1, window.Power_chart1.Port3P);
                data.setValue(1, 1, window.Power_chart1.Port2P);
                data.setValue(0, 1, window.Power_chart1.Port1P);
                chart.draw(data, options);
            }, 1000);
        }
    </script>
   </head>
   <body>
   <div id="chart_div" style="width: 400px; height: 120px;"></div>
   </body>
   </html>

thank you;

Upvotes: 0

Views: 510

Answers (1)

Naga Sai A
Naga Sai A

Reputation: 10975

document.getElementById('donutchart') was used to render pie but the element is missing .Hence it is not getting rendered. Include below

<div id="donutchart" style="width: 400px; height: 120px;"></div>

codepen -http://codepen.io/pen/

Upvotes: 1

Related Questions