Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6357845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:15:01+00:00 2026-05-24T23:15:01+00:00

I’m working on an open Source CMS based on CodeIgniter and I’m trying to

  • 0

I’m working on an open Source CMS based on CodeIgniter and I’m trying to integrate a chart system with the API of Google Analytics.

I’ve successfully retrieved the informations from Google Analytics (like visits, page views and so on) and it gives me an Array:

Array
(
    [] => Array
        (
            [ga:visits] => 800
            [ga:pageviews] => 1200
        )
    [] => Array
        (
            [ga:visits] => 400
            [ga:pageviews] => 900
        )
) ... 

Then to use the informations I’ve made a foreach loop

foreach ($report as $value) {
            echo $value["ga:visits"];
            echo '-';
        }

I’ve all my statistics with this ‘echo’ and it appears like this 1200-300-450- and so on. great until now.

Well, now I use the Charts API from Google to make a chart and I have this piece of code :

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

      // Set a callback to run when the Google Visualization API is loaded.
      google.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. I NEED TO PLACE MY RETRIEVED INFORMATIONS FROM THE FOREACH LOOP HERE :
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Month');
      data.addColumn('number', 'visits');
      data.addRows(8);
      data.setValue(0, 0, 'Day 1');
      data.setValue(0, 1, 1000);
      data.setValue(1, 0, 'Day 2');
      data.setValue(1, 1, 70);
      data.setValue(2, 0, 'Day 3');
      data.setValue(2, 1, 860);
      data.setValue(3, 0, 'Day 4');
      data.setValue(3, 1, 1030);

      // Set chart options
      var options = {
 'title':'test',
'width':1200,
'height':600,
'legend' : 'bottom',
'series' : {0:{color: 'black', pointSize : 12, visibleInLegend: true}},
'backgroundColor' : '#FFFFFF',
                };

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    } 

I just want to use my retrieved informations from the foreach loop in the ‘data.setValue(…, …, …);’ of this JS function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:15:02+00:00Added an answer on May 24, 2026 at 11:15 pm

    If I were you, I would not simple echo ga:visits, but form up an array:

    <script type='text/javascript'>
        var ga_data = [
        <?php
            $str = "";
            foreach ($report as $value)
                $str.="{$value["ga:visits"]},";
            $str = rtrim($str,",");
        echo $str;
        ?>
        ];
    </script>
    

    Note:

    • trailing , is removed. Chrome and FF just skip it, while IE8 decide that there are one more array element. So [1,2,] is [1,2] for Chrome and FF, but [1,2,undefined] for IE.
    • I have placed it in a separate script tag. It’s a good idea when it comes to PHP errors – they are not valid javascript code so they fail the whole script block they are in. So, placing PHP’s output into separate script block will not crash other JS scripts in case of PHP errors/warnings, misformed JS code, etc.

    Now, in your script you do just the following

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Month');
    data.addColumn('number', 'visits');
    data.addRows(ga_data.length*2);
    for (i=9; i<ga_data.length; i++){
        data.setValue(i, 0, 'Day '+(i+1));
        data.setValue(i, 1, ga_data[i]);
    }
    

    I think it should do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to choose a PHP open source CMS into which I will integrate an
I'm working on an open source project I'm part of called jQuery. I'm trying
I'm working with an open-source CMS that uses some very big multi dimensional arrays/objects.
I am working on an open source web-based application that communicates with Facebook. One
I working on a cms project and using a open source cms that hosted
An open-source cms I'm working on uses the following regex for validating emails: valid_regex=^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$
When working with some open source projects (in my case Joomla and Moodle), I've
I am working with an open-source UNIX tool that is implemented in C++, and
I am working on an open source C++ project, for code that compiles on
I'm working on an open source project. The original project contains comments in russian

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.