Google Visualization PHP and Javascript

947

I am creating a chart using a while loop to get the variables from a mysql query.

I am attempting to add html to the first column and it is causing the following issue: [object Object] does not fit either the Control or Visualization specification.

So, the table displays correctly but my category filters are now throwing this error. Can someone take a look at my code and see what i am missing? Thanks!

Here is my code:

 echo    "<script type='text/javascript' src='https://www.google.com/jsapi'></script>

  <body>
  <br><br>
<div id='dashboard'>
  <div style='float:left;' id='control1'></div>
  <div style='float:left;' id='control2'></div>
  <div style='float:left;' id='control4'></div>
   <br><br>
  <div style='float:left;' id='control3'></div>
  <div style='float:left;' id='control5'></div>
  <br><br>
  <div id='table'></div>
</div>
 </body>";



echo "<script>

 google.load('visualization', '1.0', {packages:['corechart', 'table', 'controls']});
google.setOnLoadCallback(drawChart);

    function drawChart()
{
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Save');
    data.addColumn('string', 'School');
    data.addColumn('string', 'State');
    data.addColumn('string', 'Scholarship Type');
    data.addColumn('string', 'Scholarship Amount');
    data.addColumn('string', 'For International');";

    while ($schools = mysql_fetch_row($schoolsearch)) {
$schoolnames = str_replace(array('.', ',', "'"), '' , $schools[2]);

echo "data.addRows([
['<input type=\"checkbox\">', '$schoolnames', '$schools[1]', '$schools[6]', '$schools[5]', '$schools[7]'],
]);";
}

echo "var name_filter = new google.visualization.ControlWrapper({
    'controlType': 'CategoryFilter',
    'containerId': 'control1',
    'options': {
        'filterColumnLabel': 'School',
    }
});

var state_filter = new google.visualization.ControlWrapper({
    'controlType': 'CategoryFilter',
    'containerId': 'control2',
    'options': {
        'filterColumnLabel': 'State',
    }
});

var scholarshiptype_filter = new google.visualization.ControlWrapper({
    'controlType': 'CategoryFilter',
    'containerId': 'control3',
    'options': {
        'filterColumnLabel': 'Scholarship Type',
    }
});

var scholarshipamount_filter = new google.visualization.ControlWrapper({
    'controlType': 'CategoryFilter',
    'containerId': 'control4',
    'options': {
        'filterColumnLabel': 'Scholarship Amount',
    }
});

var international_filter = new google.visualization.ControlWrapper({
    'controlType': 'CategoryFilter',
    'containerId': 'control5',
    'options': {
        'filterColumnLabel': 'For International',
    }
});


var table = new google.visualization.ChartWrapper({
    'chartType': 'Table',
    'containerId': 'table',
});

 var table = new google.visualization.Table(document.getElementById('table'));
table.draw(data, {
allowHtml:true,
});

var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard'));
dashboard.bind([name_filter, state_filter, scholarshiptype_filter, scholarshipamount_filter, international_filter], [table]);
dashboard.draw(data);
}

</script>
297

Answer

Solution:

I was able to fix this by placing the allowHtml in the options like this:

 var table = new google.visualization.ChartWrapper({
    'chartType': 'Table',
    'containerId': 'table',
      options: {
allowHtml: true
 },
});
358

Answer

Solution:

another option, which may work better, depending on if you want the filter to work on the html or the value it represents...

each cell in a DataTable has a value (v:) and a formatted value (f:)

you can use the formatted value for the html

where you have...

echo "data.addRows([
  ['<input type=\"checkbox\">', '$schoolnames', '$schools[1]', '$schools[6]', '$schools[5]', '$schools[7]'],
]);";

try...

echo "data.addRows([
  [{v: '', f: '<input type=\"checkbox\">'}, '$schoolnames', '$schools[1]', '$schools[6]', '$schools[5]', '$schools[7]'],
]);";

People are also looking for solutions to the problem: stripos - Filter a string in PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.