This code actually doesn't draw nothing but the title
It's uses Highcharts like an yii extension
<?php $this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'Grafico a torta'),
'chart' => array('renderTo' =>'charts'),
'credits' => array('enabled' => false),
'series' => array (
'type' => 'pie',
'name' => 'name of serie',
'data' => array (
array('Firefox', 44.2),
array('IE7', 26.6),
array('IE6', 20),
array('Chrome', 3.1),
array('Other', 5.4)
),
),
)
));
?>
It create this javascript
jQuery(window).on('load',function() {
var chart = new Highcharts.Chart(
{'chart':{'renderTo':'charts'},
'exporting':{'enabled':true},
'title':{'text':'Grafico a torta'},
'credits':{'enabled':false},
'series':{
'type':'pie',
'name':'name of serie',
'data':[
['Firefox',44.2000000000000028],
['IE7',26.6000000000000014],
['IE6',20],
['Chrome',3.1000000000000001],
['Other',5.4000000000000004]
]}});
});
I'm not able to understand whats wrong.... no js error was throwed, not console debug info, nothing ....
What I'm missing ?
Check your serie:
series:**[**{
type:'pie',
name:'name of serie',
data:[
['Firefox',44.2000000000000028],
['IE7',26.6000000000000014],
['IE6',20],
['Chrome',3.1000000000000001],
['Other',5.4000000000000004]
]}**]**
});
You are missing [] in series. Check this: http://jsfiddle.net/tqVF8/9/
use array once more for series
section =>
'series' => array (
array (
'type' => 'pie',
'name' => 'Browser share',
'data' => array (
array('Firefox', 44.2),
array('IE7', 26.6),
array('IE6', 20),
array('Chrome', 3.1),
array('Other', 5.4)
),
),
),
it works with me.
in this data is array of count of number of event.
<?php
$this->Widget('application.extensions.highcharts.HighchartsWidget',
array('options'=>array( 'title'=>array('text'=>'User Distribution'),
'tooltip'=>array('formatter'=> 'js:function() {
return "<b>"+this.point.name+"</b>: "+Math.round(this.percentage)+"%"
}'),
'credits' => array('enabled' => true),
'exporting' => array('enabled' => true),
'plotOptions'=>array('pie'=> array('allowPointSelect'=>true,'cursor'=>'pointer',
'dataLabels'=>array('enabled'=>true),
'showInLegend'=>true)
),
'series' => array(array('type'=>'pie', 'name'=>'User Distrubution',
'data' => $data,)
)
)
)
);
?>
Related
I have next variables:
$type_model = ProductTypeModel::model()->findByPk($id);
$prod = $type_model->product;
Now in $prod:
array
(
0 => ProductModel#1
(
[CActiveRecord:_new] => false
[CActiveRecord:_attributes] => array
(
'product_id' => '6'
'product_type_id' => '5'
)
...
)
1 => ProductModel#2
(
'product_id' => '8'
'product_type_id' => '5'
)
...
How i can display my products in CGridView?
Thx.
I Suppose you are using CarrayDataProvider. So in your controller
$dataProvider = new CArrayDataProvider($prod);
Here $product could be any array you want to display in CgridView. Now
In you view write this.
$gridColumns = array(
array(
'header' => 'First Name',
'value' => 'ProductTypeModel::model()->findByPk($data->product_id)->key',
'htmlOptions' => array('style' => 'text-align:center;')
),
$this->widget('zii.widgets.grid.CGridView',array('dataProvider' => $dataProvider,));
As in CarrayDataprovider array is obtained so we cant use relations in it. Thats why u have to write 'ProductTypeModel::model()->findByPk($data->product_id)->key'
Here you can display anything attribute of ProductTypeModel so u can replace above mentioned key with your desired attribute
Try this ...
it automatic convert to array data provider.
$dataProvider=new CArrayDataProvider($type_model->product);
Thanks all. By means of answers "naveen goyal" and "jailed abroad" i did like this:
$dataProvider=new CArrayDataProvider($type_model->product);
$dataProvider->keyField = 'product_id';
$this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
array(
'header' => 'Title',
'value' => 'CHtml::encode($data["product_title"])',
),
)));
Nice work for me.
I am having trouble creating a HighChart donut chart with two layers in Yii Framework.
This is the code I am using for getting a one layer chart:
<?php
$this->widget('bootstrap.widgets.TbHighCharts', array(
// .. 'options', 'chart', 'legend', ..
'series' => array(
array(
'type' => 'pie',
'name' => 'Series of Browsers',
'data' => array(array('MSIE', 55), array('Firefox',10), array('Chrome',15), array('Safari', 20)),
),
// ..
?>
But on the highchart website I can find only java examples on how to implement the 'drilldown'. Do you have a solution for implementing the same in php in Yii?
Thanks in advance for your help!
-- Edit --
In java I would have to do something like this:
drilldown: {
name: 'MSIE',
categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'],
data: [10.85, 7.35, 33.06, 2.81]
}
but what is the equivalent operation when using the widget in Yii?
Found out on my own after all. Hope this answer can help also other people.
<?php
$this->widget('bootstrap.widgets.TbHighCharts', array(
'chart' => array(
'borderColor'=>'#e5e5e5',
'type' => 'pie',
),
// .. 'options', 'legend', ..
'series' => array(
// --------- inner layer of the pie
array(
'size' => '40%',
'data' => array(
array(
'name' => //name
'y' => //value
),
array(
'name' => //name
'y' => //value
),
),
),
// -------- second layer from the inside
array(
'size' => '60%',
'innerSize' => '40%',
'data' => array(
array(
'name' => //name
'y' => //value
),
array(
'name' => //name
'y' => //value
),
),
),
// ----- add as manny layers as you need to
),
// ..
);
?>
Pay attention because layers are not directly linked one to the other. This means that you have to wisely set the values 'y's in order to make so that the bounds matches between the layers.
I have been looking how to do this and am a bit stumped.
My array is as follows:
$returndata->setup_array = array(
'General' => array(
'Main Details' => 'setup/maindets',
'Directories' => 'directories',
'Extension Allocation' => 'xtnallo',
'List Holidays' => 'setup/holidays',
'List Group VM' => 'groupvm',
'Conference Rooms' => 'confroom'
),
'Offices' => array(
'List Offices' => 'iptoffices'
),
'Users' => array(
'List Users' => 'iptusers'
),
'Phones' => array(
'List Phones' => 'iptphones'
),
);
However I have 1 item that on a certain condition(triggered by the users session) that needs to be added to the listin the general array. The section being 'View Details => setup/viewdetails'. I have tried array push (probably incorrectly) but this adds the item as another array at the end under the main array.
I want/need it to work like this:
$returndata->setup_array = array(
'General' => array(
$viewdets
'Main Details' => 'setup/maindets',
'Directories' => 'directories',
'Extension Allocation' => 'xtnallo',
'List Holidays' => 'setup/holidays',
'List Group VM' => 'groupvm',
'Conference Rooms' => 'confroom'
),
'Offices' => array(
'List Offices' => 'iptoffices'
),
'Users' => array(
'List Users' => 'iptusers'
),
'Phones' => array(
'List Phones' => 'iptphones'
),
);
$viewdets = "'View Details' => 'setup/viewdetails'";
and still be interpreted as a functioning array for use as a menu.
$returndata->setup_array['General']['View Details'] = 'setup/viewdetails'
Cheers Rick!
You can use ArrayObject to have the array as a reference:
$a = new ArrayObject();
$b = array(
"a" => $a
);
$a[] = "foo";
print_r($b);
What did you try calling array_push() on? Have you tried
array_push($returndata->setup_array['General'], $viewdets);
You would need to add the variable to the specific depth of the array you wanted it to be present. check out array_push here, there's also a short language syntax that avoids the function call:
$returndata->setup_array['General'][] = $viewdets;
I have a plugin filter installed from https://github.com/lecterror/cakephp-filter-plugin.
How can i rename the values in the dropdown bar?
Right now I can choose between:
[ ]
[0]
[1]
What I need is:
[ ]
[Agent]
[Investor]
.
public $filters = array(
'index' => array(
'Model' => array(
'Model.Tablename' => array('label' => 'Find'),
'Model.Tablename' => array(
'label' => 'Position type',
'type' => 'select',
'selectOptions' => array (
0 => 'Agent',
1 => 'Investor'
)
)
)
)
);
At the selector type I want to rename 0 to Agent and 1 to Investor.
Find it myself:
//plugincode-----> filter_form_fields
foreach ($viewFilterParams as $field) {
// Edited on 28-03-2013
// check if option type is select.
if ($field['options']['type'] == "select") {
// check for all option values ( 0,1,2,3,4 ect ) and rename it with optionNewValue
foreach ($field['options']['options'] as $optionvalue) {
$optionNewValue = $field['options']['OptionKey'][$optionvalue];
// Rename the optionvalue
$field['options']['options'][$optionvalue] = $optionNewValue;
}
}
// filtercomponent.ctp add (plugin code )
// Optionkey gives the values filter_form_fields
// use inside the controller Optionkey => array() to rename values
$options['OptionKey'] = $settings['OptionKey'];
and now you can put in the controller
'index' => array(
'Model' => array(
'Model.Tablename' => array('label' => 'Find'),
'Model.Tablename' => array(
'label' => 'Position type',
'type' => 'select',
'OptionKey' => array (
0 => 'agent',
1 => 'investor'
)
)
)
);
:D:D:D:D:D
I have the following fields in a magento adminhtml form.
On submit im expecting to grab the post, and simply dump its contents, which im doing in my saveAction.
public function saveAction()
{
if ($this->getRequest()->getPost())
{
try{
$postData = $this->getRequest()->getPost();
echo '<pre>';
print_r($postData);
exit;
the output looks as follows.
Array
(
[form_key] => I6jK6swe1EMl0wER
[carrier_code] => test
[postcode] => tescode
[sku] => 123445
)
Seeing my form is defined as:
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('instance_form', array('legend'=>Mage::helper('instance')->__('Instance Filters')));
$fieldset->addField('carrier_code', 'text', array(
'label' => Mage::helper('instance')->__('Carrier service'),
'name' => 'carrier_code',
'after_element_html' => '<small>Leave blank for all Carriers.</small>',
));
$fieldset->addField('postcode', 'text', array(
'label' => Mage::helper('instance')->__('Postcode'),
'name' => 'postcode',
'after_element_html' => '<small>Leave blank for all Postcodes.</small>',
));
$fieldset->addField('sku', 'text', array(
'label' => Mage::helper('instance')->__('Sku'),
'name' => 'sku',
'after_element_html' => '<small>Leave blank for all Skus.</small>',
));
$fieldset->addField('start_date', 'date', array(
'label' => Mage::helper('instance')->__('Start Date'),
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1,
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
));
$fieldset->addField('aura', 'file', array(
'label' => Mage::helper('instance')->__('Upload'),
'value' => 'Uplaod',
'disabled' => false,
'readonly' => true,
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1
));
I was expecting to see output like this instead :
Array
(
[form_key] => I6jK6swe1EMl0wER
[carrier_code] => test
[postcode] => tescode
[sku] => 123445
[start_date] => someValue
[aura] => anotherValue
)
am i missing something? why would say the date field, not be added to the post, like all the other text input fields?
Cheers
You're missing the name key in your addField('start_date', ..) call.
Each field of a Varien_Data_Form you want to be submittable needs a name key/value pair.
The value you assign to your field's name key is used as value for the name attribute of the corresponding <input> element when rendering the <form>.