Yii Framework Forum: Google Chart - Csqldataprovider - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Google Chart - Csqldataprovider Rate Topic: -----

#1 User is offline   GPM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 27-August 13

Posted 18 February 2014 - 04:52 PM

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
0

#2 User is offline   lgastmans 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 26-October 11
  • Location:Pondicherry, India

Posted 04 July 2014 - 01:47 AM

View PostGPM, on 18 February 2014 - 04:52 PM, said:

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


This may be way too late for you, but in case you still need help you can have a look here
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users