Hi
I am looking for a simple way to output data from my controller and populate the data in a Google chart.
I can pass the data and output the results into a test echo in my view but I am unsure how to output this inside the <script> tags?
Any help would be most appreciated.
Controller
class TheLeagueController extends Controller
{
public function actionVenue()
{
$sql='SELECT * FROM player_card WHERE player_id = 1 AND season_key = 7022014 ';
$dataProvider=new CSqlDataProvider($sql,array());
$this->render('venue', array('dataProvider' => $dataProvider,));
}
}
View
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Week', 'Points'],
['Week 1', 10], // NEED TO OUTPUT AND REPLACE DATA HERE !!!!
['Week 2', 14], // NEED TO OUTPUT AND REPLACE DATA HERE !!!!
['Week 3', 16], // NEED TO OUTPUT AND REPLACE DATA HERE !!!!
]);
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div" style="width: 100%;"></div>
Working Test View
<?php foreach($dataProvider->data as $card):?>
<div>
<?php echo $card['week_1_points']?>
<?php echo $card['week_2_points']?>
<?php echo $card['week_3_points']?>
</div>
<?php endforeach?>
10 14 16
Once again, any help would be most appreciated.
Many thanks
GPM