Re: Google Charts - Multiple line in a graph.

528 views
Skip to first unread message
Message has been deleted

asgallant

unread,
Apr 26, 2013, 1:30:49 PM4/26/13
to google-visua...@googlegroups.com
This:

[(<?=$jsonTable?>),'CSSR CS 2G'],
[(<?=$jsonTable1?>),'CSSR CS 3G'],
[(<?=$jsonTable2?>),'CSSR PS 2G'],
[(<?=$jsonTable3?>),'CSSR PS 3G']

is your problem.  Regardless of what is output by the $jsonTable variables, this structure will never be correct.  The data has to be in the form [start time, CSSR CS 2G, CSSR CS 3G, CSSR PS 2G, CSSR PS 3G] for each row of data.  I can help you get this set up correctly if you post the rest of your PHP code (the parts relevant to creating the dataTable variables).

On Friday, April 26, 2013 12:52:07 PM UTC-4, Alex wrote:
Hello 
A need a help .
My Code don't work. I don't now why. 

  <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">

    
    google.load('visualization', '1', {'packages':['coreChart']});

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

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
       var data = new google.visualization.DataTable();
       data.addColumn('string', 'start_time');
       data.addColumn('number', 'CSSR CS 2G');
       data.addColumn('number', 'CSSR CS 3G');
       data.addColumn('number', 'CSSR PS 2G');
       data.addColumn('number', 'CSSR PS 3G');
       data.addRows([
       [(<?=$jsonTable?>),'CSSR CS 2G'],
       [(<?=$jsonTable1?>),'CSSR CS 3G'],
       [(<?=$jsonTable2?>),'CSSR PS 2G'],
       [(<?=$jsonTable3?>),'CSSR PS 3G']
  ]);
     
       var options = {
          title: 'Acessibility',
          //chartArea: {width: 0, top: 30, left: 140, width: "50%", height: "50%"},
        //backgroundColor: 'yellow',  //cor do fundo do grafico 
        //axisTitlesPosition: 'out', 
          //vAxis: {title: "Valor"}, //legenda horizontal 
          //hAxis: {title: "Data"}, //legenda vertical
          //colors: ['#AA00CC'], // cor da linha do gráfico
          //is3D: 'True', 
          width: 1500, //largura
          height: 400, //Altura
      };
      
      // Instantiate and draw our chart, passing in some options.
     var chart = new google.visualization.LineChart(document.getElementById('graf31'));

     chart.draw(data,options);  
      
    }
    
    
Message has been deleted

asgallant

unread,
Apr 27, 2013, 10:10:14 AM4/27/13
to google-visua...@googlegroups.com
I joined the tables together into one query statement, which should substantially simplify things, and fixed up the DataTable creation code.  I also made a few minor edits here and there.  Try the attached file and see if it works.  If it doesn't work, open it in a browser and view the page source.  If that is empty (or contains error codes pertaining to PHP or PostgreSQL) then there is a problem in the PHP.  If it is populated, then there is a problem with the javascript.  In the latter case, copy the source from the browser and post here so I can help debug it.

On Saturday, April 27, 2013 7:41:47 AM UTC-4, Alex wrote:
   thanks my code:
<?php

  // Aceder a base de dados 
$host = "...";
$user= "...";
$pass = "....";
$db="....";

$acessoDB = pg_connect("host=$host dbname=$db user=$user password=$pass");
if (!$acessoDB){
die ("Não foi possível aceder à base de dados.");


  $queryData =pg_query("SELECT start_time, media_cssr_cs_2g_quinzenal
                              FROM huawei.quinzenal_cssr_cs_2g
                              ORDER BY start_time");
                              
 $queryData1 =pg_query("SELECT start_time, media_cssr_cs_3g_quinzenal
                              FROM huawei.quinzenal_cssr_cs_3g
                              ORDER BY start_time");
                              
 
 $queryData2 =pg_query("SELECT start_time, media_cssr_ps_2g_quinzenal
                              FROM huawei.quinzenal_cssr_ps_2g
                              ORDER BY start_time");                            

 $queryData3 =pg_query("SELECT start_time, media_cssr_ps_3g_quinzenal
                              FROM huawei.quinzenal_cssr_ps_3g
                              ORDER BY start_time");   

$table = array();
$table['cols'] = array(

 array('label' => 'start_time', 'type' => 'string'),
  array('label' => 'CSSR CS 2G', 'type' => 'number'),
  array('label' => 'CSSR CS 3G', 'type' => 'number'),
  array('label' => 'CSSR PS 2G', 'type' => 'number'),
   array('label' => 'CSSR PS 3G', 'type' => 'number')
);

//1 Series
    $rows = array();
    while($r = pg_fetch_assoc($queryData)) {
        $temp = array();
        // the following line will used to slice the Pie chart
        $temp[] = array('v' => (string) $r['start_time']); 

        //Values of the each slice
        $temp[] = array('v' => (float) $r['media_cssr_cs_2g_quinzenal']); 
        $rows[] = array('c' => $temp);
    }

    $table['rows'] = $rows;
    $jsonTable = json_encode($table);
    //echo $jsonTable;

//2 Series
    $rows = array();
    while($r = pg_fetch_assoc($queryData1)) {
        $temp = array();
        // the following line will used to slice the Pie chart
        $temp[] = array('v' => (string) $r['start_time']); 

        //Values of the each slice
        $temp[] = array('v' => (float) $r['media_cssr_cs_3g_quinzenal']); 
        $rows[] = array('c' => $temp);
    }

    $table['rows'] = $rows;
    $jsonTable1 = json_encode($table);
    //echo $jsonTable1;
    
    //3 Series
    $rows = array();
    while($r = pg_fetch_assoc($queryData2)) {
        $temp = array();
        // the following line will used to slice the Pie chart
        $temp[] = array('v' => (string) $r['start_time']); 

        //Values of the each slice
        $temp[] = array('v' => (float) $r['media_cssr_ps_2g_quinzenal']); 
        $rows[] = array('c' => $temp);
    }

    $table['rows'] = $rows;
    $jsonTable2 = json_encode($table);
    //echo $jsonTable2;
    
    //4 Series
    $rows = array();
    while($r = pg_fetch_assoc($queryData3)) {
        $temp = array();
        // the following line will used to slice the Pie chart
        $temp[] = array('v' => (string) $r['start_time']); 

        //Values of the each slice
        $temp[] = array('v' => (float) $r['media_cssr_ps_3g_quinzenal']); 
        $rows[] = array('c' => $temp);
    }

    $table['rows'] = $rows;
    $jsonTable3 = json_encode($table);
    //echo $jsonTable3;

?>


<html>
  <head>
    </script>
  </head>

  <body>
    <!--Div that will hold the chart-->
    <div id="graf31"></div>
   
  </body>
</html>
chart.php
Message has been deleted

asgallant

unread,
Apr 29, 2013, 10:02:15 AM4/29/13
to google-visua...@googlegroups.com
Ok, looks like PostgreSQL require that table a field is from in a join statement be specified.  Modify the "select" line to this:

SELECT a.start_time, a.media_cssr_cs_2g_quinzenal, b.media_cssr_cs_3g_quinzenal, c.media_cssr_ps_2g_quinzenal, d.media_cssr_ps_3g_quinzenal

On Monday, April 29, 2013 5:58:54 AM UTC-4, Alex wrote:
Hi

Thanks, but the code did not work.
 In axeno i send you the error.
Message has been deleted

asgallant

unread,
Apr 29, 2013, 1:08:47 PM4/29/13
to google-visua...@googlegroups.com
Open the chart in a browser, view the source and post it here so I can see what might be the problem.

On Monday, April 29, 2013 12:53:00 PM UTC-4, Alex wrote:
Thank you very much, now it's ok :):):):) 

I modified the code to:

$queryData =pg_query("SELECT a.start_time, a.media_cssr_cs_2g_quinzenal, b.media_cssr_cs_3g_quinzenal, c.media_cssr_ps_2g_quinzenal, d.media_cssr_ps_3g_quinzenal
FROM huawei.quinzenal_cssr_cs_2g AS a
  FULL JOIN huawei.quinzenal_cssr_cs_3g AS b ON (a.start_time = b.start_time)
FULL JOIN huawei.quinzenal_cssr_ps_2g AS c ON (a.start_time = c.start_time)
FULL JOIN huawei.quinzenal_cssr_ps_3g AS d ON (a.start_time = d.start_time)
ORDER BY a.start_time,b.start_time,c.start_time,d.start_time");

but still have a problem with the X axis.
I will analyze the problem and  I will tel you something.

knows how to work with MACRO excel?


thanks again :D :D


2013/4/29 asgallant <drew_g...@abtassoc.com>

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/gQU4-GDivoE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Cumprimentos.
Irina Lima
Message has been deleted

asgallant

unread,
Apr 29, 2013, 1:28:17 PM4/29/13
to google-visua...@googlegroups.com
At a guess, I would say that the axis label problem is due to the SQL only returning values start_time values from the first table.  You can try modifying the select again like this to fix it:

SELECT
COALESCE(a.start_time, b.start_time, c.start_time, d.start_time) AS start_time,
a.media_cssr_cs_2g_quinzenal,
b.media_cssr_cs_3g_quinzenal,
c.media_cssr_ps_2g_quinzenal,
d.media_cssr_ps_3g_quinzenal
Message has been deleted
Message has been deleted

asgallant

unread,
Apr 29, 2013, 3:24:01 PM4/29/13
to google-visua...@googlegroups.com
What is it you would like to have for the x-axis values?

On Monday, April 29, 2013 2:11:56 PM UTC-4, Alex wrote:
Also if I wanted to change the X-Axis as I do. Do I use names with or without values ?


2013/4/29 Alex <irina...@gmail.com>

THANKS :):):):):):):):)


2013/4/29 asgallant <drew_g...@abtassoc.com>
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsubscr...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Cumprimentos.
Irina Lima

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/gQU4-GDivoE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Cumprimentos.
Irina Lima
Message has been deleted

asgallant

unread,
Apr 29, 2013, 6:04:13 PM4/29/13
to google-visua...@googlegroups.com
I'm having some difficulty understanding precisely what you want.  Are you trying to get labels from geral.lac to replace the "lac" values from siemens.semanal_subscriber_per_lac?

On Monday, April 29, 2013 5:18:14 PM UTC-4, Alex wrote:

Attached please find what I want.

From the table with the data base, I want to make the graphs above with the codes I have sent to you earlier”

SELECT COALESCE(a.lac, b.ilha) as lac, a.max_subscriber_per_lac_semanal FROM siemens.semanal_subscriber_per_lac AS a 

FULL JOIN geral.lac AS b ON (a.lac = 'b.ilha')

ORDER BY a.lac,b.ilha;

 ERROR: invalid input syntax for integer: "b.ilha"

ilha is varchar and lac is integer 




2013/4/29 asgallant <drew_g...@abtassoc.com>



--
Cumprimentos.
Irina Lima
Message has been deleted

asgallant

unread,
Apr 29, 2013, 10:24:31 PM4/29/13
to google-visua...@googlegroups.com
Ok, this is the SQL you want:

SELECT b.ilha, a.max_subscriber_per_lac_semanal
FROM siemens.semanal_subscriber_per_lac AS a 
LEFT JOIN geral.lac AS b ON (a.lac = b.lac)
ORDER BY b.ilha

On Monday, April 29, 2013 6:18:39 PM UTC-4, Alex wrote:
Yes, I have 2 tables  in database. 

1 table = geral.lac 
 2 table= siemens.semanal.....


Attached please



2013/4/29 Irina lima <irina...@gmail.com>

Attached please find what I want.

From the table with the data base, I want to make the graphs above with the codes I have sent to you earlier”

SELECT COALESCE(a.lac, b.ilha) as lac, a.max_subscriber_per_lac_semanal FROM siemens.semanal_subscriber_per_lac AS a 

FULL JOIN geral.lac AS b ON (a.lac = 'b.ilha')

ORDER BY a.lac,b.ilha;

 ERROR: invalid input syntax for integer: "b.ilha"

ilha is varchar and lac is integer 




2013/4/29 asgallant <drew_g...@abtassoc.com>
What is it you would like to have for the x-axis values?



--
Cumprimentos.
Irina Lima



--
Cumprimentos.
Irina Lima
Message has been deleted

Alex

unread,
May 10, 2013, 8:32:44 AM5/10/13
to google-visua...@googlegroups.com

Hello ASGLLANT,

I need your help again. 

I need to do checkbox with value in database and show graphs. 

My difficulty  is with queries. 

asgallant

unread,
May 10, 2013, 10:01:01 AM5/10/13
to google-visua...@googlegroups.com
Can you describe exactly what it is you want here?

Irina lima

unread,
Jun 13, 2013, 5:20:48 AM6/13/13
to google-visua...@googlegroups.com
Hello good morning
I have a question and would like to know if I can clarify.
I have a chart with dates and amounts, dates exchanges wanted by name. 
how to do it?

thanks


2013/5/10 asgallant <drew_g...@abtassoc.com>
--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/gQU4-GDivoE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Cumprimentos.
Irina Lima

asgallant

unread,
Jun 13, 2013, 2:33:21 PM6/13/13
to google-visua...@googlegroups.com
I'm sorry, I still don't understand what you want.  Can you give me an example?


On Thursday, June 13, 2013 5:20:48 AM UTC-4, Alex wrote:
Hello good morning
I have a question and would like to know if I can clarify.
I have a chart with dates and amounts, dates exchanges wanted by name. 
how to do it?

thanks


2013/5/10 asgallant <drew_g...@abtassoc.com>
Can you describe exactly what it is you want here?


On Friday, May 10, 2013 8:32:44 AM UTC-4, Alex wrote:

Hello ASGLLANT,

I need your help again. 

I need to do checkbox with value in database and show graphs. 

My difficulty  is with queries. 

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/gQU4-GDivoE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Cumprimentos.
Irina Lima
Reply all
Reply to author
Forward
0 new messages