CodeIgniter Forums

Full Version: gVis - Google Visualization Library
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

Hello CI community. You guys have been great to me over the year, I've accomplished some great stuff using CI and your help on the forums. Thank you all! So I felt like its time to give back. Here is my contribution:

gVis - a Google Visualization Library

Google visualizations is an amazing free tool released by Google. I use it for almost all of my charting and visualizations. My goal with gVis is to make it as easy to use as the CI table library. Its definitely a rough start but I think its pretty handy, and I hope that you will find it useful as well. Comments and suggestions are always appreciated, and if you have any improvements please share them with me, because I would love to make this a full fledged CI library.

Here is the wiki to the Visualization
gVis - Google Visualization Library

I'm by no means a JS or PHP ninja, but I have a solid understanding on how Google Visualizations and CI work so if you run in to trouble I might be of assistance.


El Forum

Thanks! Good contribution!

El Forum


I've been trying to use flot over the past couple of weeks to provide nice interactive graphs, but this looks a pretty good alternative at first glance. Did you consider flot, or rapheal as an alternative?

Do you have any working demos anywhere we could see? Other than googles demos that is...

El Forum

I've worked with a couple of other Flash/PHP charting tools in the past, but none of them really stuck with me or they usually cost money for the more extended features. I started to use gVisualizations because my director would always come up to me and say "wouldn't it be cool if we had the Google Finance annotated time line on so and so", he would usually throw out ideas and I would try to make them work.

The nice thing about Google Visualizations is it well maintained, there are lots of charts, graphs, and maps to choose from, and the data inputs are the same across all of the visualizations, lots of of configuration options, and its free to use! (Thats considering you don't mind your numbers being sent to Google, *puts on tinfoil hat*).

I don't have any live examples just yet. Most of my work is on the intranet, on private databases. But pretty soon I'll put together a Demo page.

Thanks for the comments!

El Forum

Excellent stuff. I guess I've never had any need to look at google finance before (being skint!).


El Forum

never heard about this one...
but thanks for sharing it - bookmarkedSmile

El Forum


could you implement that kind of chart?

Yes you can minus the animation part of it. Here is a code snippet of how I would do it



$this->gvis->set_heading('string', 'Company');
$this->gvis->set_heading('number', 'Brand Value');

$this->gvis->add_row('Coca-Cola', 67000000);
$this->gvis->add_row('Microsoft', 55000000);
$this->gvis->add_row('IBM', 50000000);
$this->gvis->add_row('GE', 48000000);

//Add more companies as needed.



There are some more parameters you would need to add in order to make it exactly like the one you have but this I think is fairly close.
Here is an image of the output:

El Forum

Your snippet works great but..

        $this->gvis->set_heading('string', 'Odpowiedz');
        $this->gvis->set_heading('number', 'Ilosc glosow');

        foreach ($rows as $row) {
            $answer = (string)$row->answer;
            $votes = (int)$row->votes;
            $this->gvis->add_row($answer , $votes);

        $googleVisualization = $this->gvis->generate();
        $data['googleVisualization'] = $googleVisualization;
        $this->load->view('poll_reply', $data);

the var dump of $row shows:

  public 'votes' => string '6' (length=1)
  public 'question_id' => string '3' (length=1)
  public 'answer' => string 'Can we go home now plz?' (length=23)

  public 'votes' => string '4' (length=1)
  public 'question_id' => string '1' (length=1)
  public 'answer' => string 'I need money' (length=12)

  public 'votes' => string '3' (length=1)
  public 'question_id' => string '2' (length=1)
  public 'answer' => string 'Epic fail!' (length=10)

  public 'votes' => string '2' (length=1)
  public 'question_id' => string '4' (length=1)
  public 'answer' => string 'Something' (length=9)

The votes are String but i cast them to integer
Your code shows me the chart, mine - shows me nothing Smile

What i did wrong?


I think that the problem is in add_row . What problem - have no idea but when i'm adding the values manualy like add_row('X', 8); it works.

El Forum

Can you send me what is outputted when you use

Also I would install firebug, it will help you find errors that the Google Visualization JS Library is throwing.

Another good tool is google visualization playground, which can be found here:

El Forum

I don't know why - but now it worksWink

I ran the site, checked out, and see a beautiful chartSmile
Pages: 1 2