示例#1
0
    /**
     * (non-PHPdoc)
     * @see \GoogleCharts\GoogleChart::__invoke()
     */
    public function __invoke($id, array $attributes = array(), $title, $data)
    {
        parent::__invoke($id, $attributes, $title, $data);
        $js = '
        	google.load("visualization", "1", {packages:["corechart"]});
			google.setOnLoadCallback(drawChart);
			function drawChart() {
				var data = google.visualization.arrayToDataTable([
		          	[\'Year\', \'Sales\', \'Expenses\'],
		          	[\'2004\',  1000,      400],
		          	[\'2005\',  1170,      460],
		          	[\'2006\',  660,       1120],
		          	[\'2007\',  1030,      540]
		        ]);

				var options = {
					title: \'' . $title . '\',
					hAxis: {title: \'Year\', titleTextStyle: {color: \'red\'}}
				};

				var chart = new google.visualization.ColumnChart(document.getElementById(\'' . $id . '\'));
				chart.draw(data, options);
    		};';
        $this->getView()->inlineScript()->appendScript($js);
        return $this->renderHtml($id, $attributes);
    }
示例#2
0
文件: PieChart.php 项目: arbi/MyCode
    /**
     * (non-PHPdoc)
     * @see \GoogleCharts\GoogleChart::__invoke()
     */
    public function __invoke($id, array $attributes = array(), $title, $data)
    {
        parent::__invoke($id, $attributes, $title, $data);
        $js = '
        	google.load("visualization", "1", {packages:["corechart"]});
			google.setOnLoadCallback(drawChart);
			function drawChart() {
				var data = google.visualization.arrayToDataTable([
				[\'Partner\', \'Bookings per Partner\'],';
        foreach ($data as $row) {
            $js .= "['" . $row->getSectionTitle() . "', " . $row->getCount() . "],";
        }
        $js .= '
    			]);

				var options = {
					title: \'' . $title . '\'
				};

				var chart = new google.visualization.PieChart(document.getElementById(\'' . $id . '\'));
				chart.draw(data, options);
    		};';
        $this->getView()->inlineScript()->appendScript($js);
        return $this->renderHtml($id, $attributes);
    }