Welcome Guest, Not a member yet? Register   Sign In
gVis - Google Visualization Library
#1

[eluser]whobutsb[/eluser]
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.

Cheers,
Steve
#2

[eluser]Sbioko[/eluser]
Thanks! Good contribution!
#3

[eluser]mattthehoople[/eluser]
Cool.

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...
#4

[eluser]whobutsb[/eluser]
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!
#5

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

Cheers.
#6

[eluser]hugle[/eluser]
never heard about this one...
but thanks for sharing it - bookmarkedSmile
#7

[eluser]whobutsb[/eluser]
Quote:Hi,

could you implement that kind of chart?
http://tinyurl.com/yh39a3m


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

Code:
$this->load->library('gvis');

$this->gvis->set_visualization('BarChart');

$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.

$this->gvis->set_is3D(true);

$this->gvis->generate();

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:

http://i.imgur.com/8iqpQ.jpg
#8

[eluser]naim[/eluser]
Your snippet works great but..

Code:
$this->load->library('gvis');
        
        $this->gvis->set_visualization('BarChart');
        $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);
            //var_dump($row);
        }

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

the var dump of $row shows:

Code:
object(stdClass)[18]
  public 'votes' => string '6' (length=1)
  public 'question_id' => string '3' (length=1)
  public 'answer' => string 'Can we go home now plz?' (length=23)

object(stdClass)[19]
  public 'votes' => string '4' (length=1)
  public 'question_id' => string '1' (length=1)
  public 'answer' => string 'I need money' (length=12)

object(stdClass)[20]
  public 'votes' => string '3' (length=1)
  public 'question_id' => string '2' (length=1)
  public 'answer' => string 'Epic fail!' (length=10)

object(stdClass)[21]
  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?

\\ EDIT

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.
#9

[eluser]whobutsb[/eluser]
Morning,
Can you send me what is outputted when you use
Code:
$this->gvis->generate()

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:
http://code.google.com/apis/ajax/playgro...ualization
#10

[eluser]naim[/eluser]
I don't know why - but now it worksWink
Damn..

I ran the site, checked out, and see a beautiful chartSmile




Theme © iAndrew 2016 - Forum software by © MyBB