One or more participants failed to draw()× Invalid column index 3. Should be an integer in the range [0-2].

108 views
Skip to first unread message

Steen Horshauge

unread,
Apr 11, 2018, 10:50:07 AM4/11/18
to Google Visualization API
I have a problem showing 3 temperature lines.
What am I doing wrong ?

Her is my php code
 $data = array();
    $data
[ 'cols' ][] = array(
                           
'label' => 'Dato',
                           
'type' => 'date'
                       
);
    $data
[ 'cols' ][] = array(
                           
'label' => 'temp 1',
                           
'type' => 'number'
                       
);
    $data
[ 'cols' ][] = array(
                           
'label' => 'temp 2',
                           
'type' => 'number'
                       
);
    $data
[ 'cols' ][] = array(
                           
'label' => 'temp 3',
                           
'type' => 'number'
                       
);

 foreach($bescale_veightlistsql as $bescale_veightlist) {
        $row
= array();
        $year
= date('Y', $bescale_veightlist->dato);
       
// JSON months zero indexed, so -1
        $month
= date( 'n', $bescale_veightlist->dato) - 1;
        $day
= date( 'j', $bescale_veightlist->dato);
        $row
[]['v'] = "Date($year,$month,$day)";

        $row
[]['v'] = $bescale_veightlist->tempext;
        $row
[]['v'] = $bescale_veightlist->tempext2;
        $row
[]['v'] = $bescale_veightlist->tempint;
        $data
['rows'][]['c'] = $row;
   
}

   
return json_encode($data);
}

And my google charts
function drawVisualization_temp(data1) {

 
var data  = new google.visualization.DataTable(data1);
  dashboard
= new google.visualization.Dashboard(document.getElementById('dashboard'));

  rows_stop
= data.getNumberOfRows()-1;

   control
= new google.visualization.ControlWrapper({
       
'controlType': 'ChartRangeFilter',
       
'containerId': 'control',
       
'options': {
           
// Filter by the date axis.
           
'filterColumnIndex': 0,
           
'ui': {
               
'chartType': 'LineChart',
               
'chartOptions': {
                 
'chartArea': {'width': '90%'},
                 
'hAxis': {'baselineColor': 'none'}
               
},
               
'chartView': {
                 
'columns': [0, 1]
               
},
               
'minRangeSize': 1
           
}
       
},
       
// Initial range: 1 to 4.
       
'state': {'range': {'start': 0, 'end': rows_stop}},
         view
: {
            columns
: [{
                type
: 'number',
                calc
: function (dt, row) {
                   
return {v: row, f: dt.getFormattedValue(row, 0)};
               
}
           
}, 1,2]
       
}
   
});



   
//then reverse the process in the ChartWrapper's view.columns:
   
   
var chart = new google.visualization.ChartWrapper({
       
'chartType'  : 'LineChart',
       
'containerId': 'chart',
       
'dataTable'  : data,
       
'options'    : {
       
'title'      : 'Test',
           
// Use the same chart area width as the control for axis alignment.
           
'chartArea': {'height': '80%', 'width': '90%'},
           
'hAxis': {'slantedText': false},
           
'vAxis': { 'format':'#,###.##' },
           
'legend': {'position': 'top'},
       
},

        view
: {
            columns
: [{
                type
: 'string',
                label
: data.getColumnLabel(0),
                calc
: function (dt, row) {
                   
return dt.getFormattedValue(row, 0);
               
}
           
}, 1,2,3]
       
}
   


 
});
     
         dashboard
.bind(control, chart);
         dashboard
.draw(data);

 
     
}


And output from json_encode
{"cols":[{"label":"Dato","type":"date"},{"label":"temperatur
1"
,"type":"number"},{"label":"temperatur
2"
,"type":"number"},{"label":"Udvendig
temperatur"
,"type":"number"}],"rows":[{"c":[{"v":"2017-12-31T23:00:00.000Z"},{"v":"19.25"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-01T23:00:00.000Z"},{"v":"19.25"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-02T23:00:00.000Z"},{"v":"19.25"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-03T23:00:00.000Z"},{"v":"19.25"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-04T23:00:00.000Z"},{"v":"19.18"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-05T23:00:00.000Z"},{"v":"19.25"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-06T23:00:00.000Z"},{"v":"19.18"},{"v":"0.00"},{"v":"21.00"}]},{"c":[{"v":"2018-01-07T23:00:00.000Z"},{"v":"19.25"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-08T23:00:00.000Z"},{"v":"19.18"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-09T23:00:00.000Z"},{"v":"19.18"},{"v":"0.00"},{"v":"20.93"}]},{"c":[{"v":"2018-01-10T23:00:00.000Z"},{"v":"19.25"},{"v":"0.00"},{"v":"21.00"}]},


Message has been deleted

Steen Horshauge

unread,
Apr 12, 2018, 12:30:46 PM4/12/18
to Google Visualization API
I do not know why, but now it works with 1,2,3] in both places

My ChartWrapper only shows one line with it's ok

           
}, 1,2,3]
Reply all
Reply to author
Forward
0 new messages