Yii Framework Forum: OpenFlashChart2Widget - Yii Framework Forum

Jump to content

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

OpenFlashChart2Widget

#1 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 280
  • Joined: 15-March 09

Posted 20 February 2011 - 06:40 PM

OpenFlashChart2Widget is a simple wrapper for OpenFlashChart2 objects. It was inspired by the extension YiiOpenFlashChart, but doesn't try to provide a new API to the open flash chart library. Instead, the Widget that comes with this extension takes an object, created using open flash chart's PHP language binding. This has the benefit, that this API is already documented, tutorials and examples are available, and the open flash chart community knows the API and can help.

Posted Image

Requirements

I don't know for sure what the minimal requirements are. I developed the extension using Yii 1.1.5, but since it doesn't do anything fancy, I'd guess it will also work with much older versions of Yii.

However, the demo application, that is included in the extension, uses action parameter binding. So this will need at least Yii v1.1.4

Installation

  • Extract folder "OpenFlashChart2Widget" in the release file to protected/extensions
  • Configure your application to find OpenFlashChart2Loader


Usage

First of all, let the OpenFlashChart2Loader initialize everything

OpenFlashChart2Loader::load();


Second, create the open flash chart object using their PHP language binding

  $bar = new bar_dome();
  $bar->set_values( array(9,8,7,6,5,4,3,2,1) );
  
  $chart = new open_flash_chart();
  $chart->set_title( new title("MyChart") );
  $chart->add_element( $bar );


Third, instantiate the widget and pass the $chart object to it.

$this->widget(
  'application.extensions.OpenFlashChart2Widget.OpenFlashChart2Widget',
  array(
    'chart' => $chart,
    'width' => '100%'
  )
);


Resources



Change Log

March 27, 2011

Minor Bug fix release - v1.0.1

  • loader doesn't touch php include path any longer
  • demo app validates user input


February 21, 2011

  • Initial release

Don't like ads in my sig...
0

#2 User is offline   siskalandre 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 92
  • Joined: 16-March 11
  • Location:Indonesia

Posted 03 July 2011 - 05:34 PM

I need your help, I have an error :

Error calling method on NPObject

i reload openflashchart2widget via javascript

<script type="text/javascript">
function reload()
{
  tmp = findSWF("openFlashChart2_0");
  x = tmp.load();
}
function findSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft")!= -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}
</script>


thank you
0

#3 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 280
  • Joined: 15-March 09

Posted 03 July 2011 - 07:19 PM

I'm sorry, but for me this looks like a generic flash-related error, nothing specific to the widget. And honestly, I don't know very much about working with flash.

But may I ask what you're trying to do? Because just in case you're trying to modify what the chart displays, then the homepage of the original openfalshchart2 component might help. They have a example, where they toggle the content of a chart, and at least to me it looks similar to what you're trying to do. The only difference is, that they pass new data to the tmp.load() method.

So, if you try the following:

<script type="text/javascript">

function reload()
{
  tmp = findSWF("openFlashChart2_0");
  x = tmp.load( open_flash_chart_data("someNonExisitingId") );
}

[...]

</script>


Then your graph should be replaces with an example bar graph.
Don't like ads in my sig...
0

#4 User is offline   siskalandre 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 92
  • Joined: 16-March 11
  • Location:Indonesia

Posted 04 July 2011 - 06:47 AM

View PostBen, on 03 July 2011 - 07:19 PM, said:

I'm sorry, but for me this looks like a generic flash-related error, nothing specific to the widget. And honestly, I don't know very much about working with flash.

But may I ask what you're trying to do? Because just in case you're trying to modify what the chart displays, then the homepage of the original openfalshchart2 component might help. They have a example, where they toggle the content of a chart, and at least to me it looks similar to what you're trying to do. The only difference is, that they pass new data to the tmp.load() method.

So, if you try the following:

<script type="text/javascript">

function reload()
{
  tmp = findSWF("openFlashChart2_0");
  x = tmp.load( open_flash_chart_data("someNonExisitingId") );
}

[...]

</script>


Then your graph should be replaces with an example bar graph.


Thanks Ben for your reply. I had that error, when I use ajax to reload (or load) flash chart.

I had fixed my problem.
this is my code.

in my controller:
public function actionIndex()
	{
	  if (isset($_GET['yearFrom']))
	  {
		  Yii::app()->user->setState('yearFrom',(int)$_GET['yearFrom']);
		  unset($_GET['yearFrom']);  // would interfere with pager and repetitive page size change
	  }
	  if (isset($_GET['yearTo']))
	  {
		  Yii::app()->user->setState('yearTo',(int)$_GET['yearTo']);
		  unset($_GET['yearTo']);  // would interfere with pager and repetitive page size change
	  }
	  if (isset($_GET['account']))
	  {
		  Yii::app()->user->setState('yearTo',(int)$_GET['yearTo']);
		  unset($_GET['yearTo']);  // would interfere with pager and repetitive page size change
	  }
	  OpenFlashChart2Loader::load();
	  $bar = new bar_filled( '#E2D66A', '#577261' );

	  if (isset($_POST['yearfrom']))
	  {
		$yearfrom = (int)$_POST['yearfrom'];
		$yearto = (int)$_POST['yearto'];
		$chart = new open_flash_chart();
		$chart->set_title( new title("General Ledger") );
		$accounts=Account::model()->findAllByAttributes(array('accountcode'=>$_POST['accountcode']));
		$xarray = array();
		$maxvalue = 0;
		$minvalue=0;
		foreach($accounts as $account)
		{
		  $connection=Yii::app()->db;
		  $sql = 'select sum(Debit-Credit) as currvalue from genledger where accountid = '.$account->accountid.' and year(postdate) between '.$_POST['yearfrom'].' and '.$_POST['yearto'].' group by year(postdate)';
		  $command=$connection->createCommand($sql);
		  $dataReader=$command->query();
		  $datas=array();
		  foreach($dataReader as $row)
		  {
			if ($row['currvalue'] != null)
			{
			$datas[]= (float) $row['currvalue'];
			}
			else
			  $datas[]= 0;
		  }
		  if (count($datas)>0) {
			$maxvalue = max($datas);
			$minvalue = min($datas);
		  }
		  $bar->set_values( $datas );
		  $chart->add_element( $bar );
		}
		for($i=$yearfrom;$i<=$yearto;$i++) {
		  $xarray[]=(string)$i;
		}
		$x = new x_axis();
		$x->set_labels_from_array($xarray);
		$chart->set_x_axis( $x );
		$y = new y_axis();
		if ($minvalue < 0) {
		$y->set_range( $minvalue, $maxvalue, 10);
		} else {
		  $y->set_range( 0, $maxvalue, 10);
		}
		$chart->set_y_axis( $y );
		echo CJSON::encode(array(
			  'status'=>'success',
			  'data'=>$chart->toPrettyString()
			));
	  }
	  else {
	  $this->render('index',array(
		  'model'=>$model,
		  'chart'=>$chart
	  ));
	  }
	}


in my view:
<?php
$this->breadcrumbs=array(
	'Genledgers',
);
$yearfrom=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultYearFrom']);
$yearto=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultYearTo']);
?>
<script type="text/javascript">
function findSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft")!= -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}
</script>
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
    'id'=>'helpdialog',
    'options'=>array(
        'title'=>'Help',
        'autoOpen'=>false,
        'modal'=>true,
        'width'=>550,
        'height'=>470,
    ),
));?>
<?php echo $this->renderPartial('_help'); ?>
<?php $this->endWidget();?>
<h1>General Ledger</h1>
<?php
$imghelp=CHtml::image(Yii::app()->request->baseUrl.'/images/help.png');
echo CHtml::link($imghelp,'#',array(
   'style'=>'cursor: pointer; text-decoration: underline;',
   'onclick'=>"$('#helpdialog').dialog('open');",
   'title'=>Yii::t('app','help')
));?>
<?php 
$this->widget(
  'application.extensions.OpenFlashChart2Widget.OpenFlashChart2Widget',
  array(
    'chart' => $chart,
    'width' => '100%',
	'height' => 400,
  )
);
?>
<form action="index.php?r=genledger/index" method="POST">
Year From : <?php echo CHtml::textField('yearfrom',$yearfrom,array('size'=>'5',
        // change 'user-grid' to the actual id of your grid!!
	  ));  ?>
To : <?php echo CHtml::textField('yearto',$yearto,array('size'=>'5',
        // change 'user-grid' to the actual id of your grid!!
	  ));  ?>
Account Code : <?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
	'name'=>'accountcode',
	'value'=>'',
	'source'=>$this->createUrl('genledger/getaccount'),
	// additional javascript options for the autocomplete plugin
	'options'=>array(
			'showAnim'=>'fold',
	),
));  ?><br/><?php echo CHtml::ajaxSubmitButton('Submit',
		array('genledger/index'),
	  array(
	  'success'=>'function(data)
		{
			var x = eval("(" + data + ")");
			if (x.status == "success")
			{
			  [b]tmp = findSWF("openFlashChart2_0");
			  tmp.load(x.data);[/b]
			}
        }')); ?>
</form>
<div id="message"></div>

0

#5 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 280
  • Joined: 15-March 09

Posted 04 July 2011 - 07:51 AM

I'm glad it's working now. And thanks for sharing your code. In fact, lazy loading/ updating chart data has always been on my TODO list, but I never found time to try it. :)
Don't like ads in my sig...
0

#6 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 280
  • Joined: 15-March 09

Posted 02 November 2011 - 09:40 AM

Just configured anonymous read access for the repository. It contains the widgets source code as well as the demos source code, which I didn't prepare as download earlier.
Don't like ads in my sig...
0

#7 User is offline   foonmod 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 27-January 12

Posted 09 March 2012 - 12:55 AM

Hi , I'm newbie ,
I try a demo but show error like below

An error occured while initializing yii. Please have a look at the file "C:\AppServ\www\demo\initializeYii.php" and fix its settings. Without modifications, it assumes yii is in your php include path.


Help to explain me please ...

Foonmod
0

#8 User is offline   foonmod 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 27-January 12

Posted 09 March 2012 - 03:56 AM

Alias "OpenFlashChart2Widget.OpenFlashChart2Widget" is invalid. Make sure it points to an existing PHP file.

Above is the error message I have got once I try to open a demo.

any suggestion please..

foonmod
0

#9 User is offline   foonmod 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 27-January 12

Posted 09 March 2012 - 04:49 AM

I can fix it already ...
Thank you

foonmod
0

#10 User is offline   A.Miguel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 12-October 11

Posted 17 April 2012 - 01:12 PM

Hi,

Does anybody know how to get those graphs exported into PDF/Image/Excel/...?

Thanks
A.Miguel
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