Line chart - Display data-sets depending on other column (if/then)

67 views
Skip to first unread message

Nadja

unread,
Mar 7, 2016, 12:47:05 PM3/7/16
to Google Visualization API
Hello,

I have a line chart with data from a database.
In the database I have a column called "error", where numbers or characters reflect the error code (e.g. 0=no error, A=Error in size, B=Error in....).
If the error is not equal to "0" the data-set for this entry shall not be displayed in the graph; there should be a marker for this data-set (*/asterix/color-coded/...) to reflect that this data-set has an error.
In principle I need the good old "if/then" function; IF the error-column is <>0, THEN display * or whatever...
Can somebody help me, how to fix this with google line charts?
Thank you
Nadja

Nadja

unread,
Mar 10, 2016, 2:12:58 AM3/10/16
to Google Visualization API
Can nobody help me?
Or do you not understand what I mean?
Nadja

Daniel LaLiberte

unread,
Mar 10, 2016, 9:51:02 AM3/10/16
to Google Visualization API
Hi Nadja,

It is not exactly clear what you are asking for, but if you prepare your data appropriately, I believe you can get the effect you want.  Look into using the 'role' column:  https://developers.google.com/chart/interactive/docs/roles#what-are-roles  and perhaps use a DataView with a calculated column to build the appropriate table:  https://developers.google.com/chart/interactive/docs/reference#dataview-class   

If you put together an example that we can look, we could perhaps help you more.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/dfaff0db-a141-4b56-b3ec-c3e548aa7441%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Nadja

unread,
Mar 15, 2016, 11:36:09 AM3/15/16
to Google Visualization API
Thank you Daniel.
I thins the role column is the right one for me.
I tried it like this:
Preparing the Data from the Database:
if ($dataobject->error=="0"){
              $error
=null;    
           
}else $error= "X" ;
       
if($error=="X"){
            $intmin
=0;
            $intmax
=4000;
       
}else{
          $intmin
=null;
          $intmax
=null;
       
}

$data1
=array($timed." ".$hourd);
       
if(isset($cha1)) $data1[]=$chad1;
       
if(isset($cha2)) $data1[]=$chad2;
       
if(isset($cha3)) $data1[]=$chad3;
       
if(isset($temp)) $data1[]=$tempd;
        $data1
[]=$intmin;
        $data1
[]=$intmax;
        $data1
[]=$error;
        $data1
[]=$errortext;
       
       
        $data
[]=$data1;

$chart_data
= json_encode($data);

in the Javascript-part I have the following code:
 var data = new google.visualization.DataTable();
      data
.addColumn('string', 'Time');
     
if(<?php if(isset($cha1)) echo $cha1; else echo "0"; ?>==1) {data.addColumn('number', 'Zone 1');}
     
if(<?php if(isset($cha2)) echo $cha2; else echo "0"; ?>==1){ data.addColumn('number', 'Zone 2');}
     
if(<?php if(isset($cha3)) echo $cha3; else echo "0"; ?>==1) {data.addColumn('number', 'Zone 3');}
     
if(<?php if(isset($temp)) echo $temp; else echo "0"; ?>==1) {data.addColumn('number', 'Temp');}
     
      data
.addColumn({type:'number', role:'interval'});  // interval role col.
      data
.addColumn({type:'number', role:'interval'});  // interval role col.
      data
.addColumn({type:'string', role:'annotation'}); // annotation role col.
       data
.addColumn({type:'string', role:'annotationText'}); // annotationText col.
     
     
     data
.addRows(<?php echo $chart_data ?>);


The chart is drawing but I cannot see my annotations "X" and my annotationtext.
Can somebody help me?
Thank you

Nadja

Am Montag, 7. März 2016 18:47:05 UTC+1 schrieb Nadja:

Daniel LaLiberte

unread,
Mar 15, 2016, 11:51:25 AM3/15/16
to Google Visualization API
Hi Nadja,

You should look at what ends up in your browser.  Use view source, or better, js developer tools, depending on your browser.  Maybe you'll discover what went wrong.  If not, we might be able to help more if you could point us at your web page.  You can send me a link privately if you want.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.

Nadja

unread,
Mar 15, 2016, 12:15:24 PM3/15/16
to Google Visualization API
In firebug I cannot find an error.
But could be the other code the problem?
On my site you can select the channels and in the javascript I'm "asking" whitch channels to display.
Here is the code for all channels:
 if(<?php if(isset($axe)) echo $axe; else echo "0"; ?>==1){  
     
var options = {
        chart
: {
          title
: 'Data'
       
},
       
        height
:600,        
        chartArea
:{left:30,top:30,width:'100%',height:600},
        series
: {
         
// Gives each series an axis name that matches the Y-axis below.
         
         
0: {axis: 'ppm'},
         
1:{axis: 'ppm'},
         
2:{axis: 'ppm'},
         
3:{axis: 'C'},
         
       
},
        axes
: {
         
// Adds labels to each axis; they don't have to match the axis names.
         y
: {
            ppm
: {label: '<?php echo $unitaktuell ?>'},
            C
: {label: '°C'}

         
}
       
}

     
};}


 
var chart = new google.charts.Line(document.getElementById('linechart_material'));

      chart
.draw(data, options);

If this is not the problem I ask for an account for you.
Thank you for your help

Nadja

Am Montag, 7. März 2016 18:47:05 UTC+1 schrieb Nadja:

Daniel LaLiberte

unread,
Mar 15, 2016, 12:43:54 PM3/15/16
to Google Visualization API
I can't tell enough from your php code what is going on. So if you need to give me access to your web page, that sounds like the simplest way to proceed.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages