Dynamically update highcharts via setData for Yii-created Highcharts Widget - yii

Is it possible to update a highcharts chart using the chart.series[i].setData method if the chart has been created by the Yii extension? I have used highcharts before without Yii extension and able to reference my variables once I set the chart up via declared variable var chart = .... I would just like to to able to call the setData methods for a Yii-created highcharts...this is current code for creating chart:
$this->Widget('ext.highcharts.HighchartsWidget', array(
'id' => 'shop_pie',
'options' => array(
'chart' => array(
'backgroundColor' => '#efefef'
),
'colors' => $colors,
'title' => array('text' => 'Shop'),
'plotOptions' => array(
'pie' => array(
'showInLegend' => 'true',
'dataLabels' => array(
'formatter' => 'js:function(){return this.point.y}',
'distance' => -10,
'color' => '#000'
),
),
'series' => $results['series'],
)
));
My ajax call to update the chart:
"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
//chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",
Many thanks in advance.
Andy

"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
var chart = $('#shop_pie').highcharts();
chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",
referring to
http://api.highcharts.com/highcharts#Series.setData
and example from that article
http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/series-setdata/

Related

Difference between THEME_preprocess_image and THEME_image ?

What is the difference between these 2 functions that can but put in template.php for Drupal?
function THEME_preprocess_image(&$variables) {
// something
}
function THEME_image($variables) {
// something
}
function theme_image renders the HTML output for a renderable array.
THEME_preprocess_image
I do believe, that the right name for that is template_preprocess_HOOK, it is called inside of theme() before theme function eg. THEME_image
Please consider the use case here:
// In custom.module
$variables = array(
'path' => 'path/to/img.jpg',
'alt' => 'Test alt',
'title' => 'Test title',
'width' => '50%',
'height' => '50%',
'attributes' => array('class' => 'some-img', 'id' => 'my-img'),
);
$img = theme('image', $variables);
If you want to change some attributes of an image, you do the following:
function mytheme_preprocess_image($vars) {
// Do the changes, before it's rendered.
}

link in cgridview is not displaying correctly

It appears that the links aren't in correct order and I can't figure out why. I have it in other grids, they seem to be fine.
This is what the link shows:
index.php?ajax=gridID&id=180&r=controller/action
when it's suppose to show:
index.php?r=controller/action&id=180
this is my value in gridview:
'value'=>function($data,$row){
if (intval($data->sid) ==$someID){
if($data->accept == "ACCEPTED")
return CHtml::Link("[X]", array("controller/action","id"=>$data->id),
array('confirm' => 'Are you sure?',
'class'=>'stat')
);
}
where grid is suppose to refresh on confirm:
<?php
Yii::app()->clientScript->registerScript('stat', "
$('#gridId a.stat').live('click', function() {
$.fn.yiiGridView.update('gridId', {
type: 'POST',
url: $(this).attr('href'),
success: function() {
$.fn.yiiGridView.update('gridId');
}
});
return false;
});"
);
?>
if you need generate url on "path" format (controller/action/id/180) and without script name you can set urlFormat property in UrlManager to "path" and set showScriptName property to false. Look this and this
in aplication config file:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
)

Yiibooster TBSelect2 not displayed

In my view I have this code:
echo $form->select2Row($model, 'Zustelladresse', array(
'asDropDownList' => false,
'options' => array(
'placeholder' => "Zustelladresse",
'width' => '100%',
'closeOnSelect' => true,
'minimumInputLength'=>1,
'initSelection' => "js:function (element, callback) {
var selected_data = new Object;
selected_data.id = '123';
selected_data.text = 'Test';
callback(selected_data);
}",
'ajax' => array(
'url' => Yii::app()->createUrl('address/zustelladresse'),
'dataType' => 'json',
'data' => 'js:function(term,page) { if(term && term.length){ return { zustelladresse: term };} }',
'results' => 'js:function(data,page) { return {results: data}; }',
),
)));
Created html:
Why is created only label and hidden input?
YiiBooster widgets are quite tricky to debug, if anything is wrong they just don't show. If you still need the answer, I successfully displayed a select2 widget with this code:
$form->select2Row($model, 'attribute_name', array(
'data' => array('1'=>'value1,'2'=>'value2'),
'htmlOptions'=>array(
'style' => 'width:600px',
'multiple' => true,
),
'options'=>array('placeholder'=>'Please make a selection'),
));
I'd suggest you to start from this code and add up your options one by one, and see if anything breaks.

Yii select2 - returned data cannot be selected

I have been looking into select2 and yii and have managed to load data via json request/response.
The issue I'm faced with is when I try to select an entry of the returned data, I can not.
Where am I going wrong ? The data returnd by the action is json formatted as CustomerCode and Name
Widget code in form
$this->widget('bootstrap.widgets.TbSelect2', array(
'asDropDownList' => false,
'name' => 'CustomerCode',
'options' => array(
'placeholder' => 'Type a Customer Code',
'minimumInputLength' => '2',
'width' => '40%',
'ajax' => array(
//'url'=> 'http://api.rottentomatoes.com/api/public/v1.0/movies.json',
'url'=> Yii::app()->getBaseUrl(true).'/customer/SearchCustomer',
'dataType' => 'jsonp',
'data' => 'js: function (term,page) {
return {
term: term, // Add all the query string elements here seperated by ,
page_limit: 10,
};
}',
'results' => 'js: function (data,page) {return {results: data};}',
),
'formatResult' => 'js:function(data){
var markup = data.CustomerCode + " - ";
markup += data.Name;
return markup;
}',
'formatSelection' => 'js: function(data) {
return data.CustomerCode;
}',
)));
code snipped from controller action SearchCustomer
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderJSON(Customer::model()->searchByCustomer($term));
renderJSON function from base controller class
protected function renderJSON($data)
{
header('Content-type: application/json');
echo $_GET['callback'] . "(";
echo CJSON::encode($data);
echo ")";
foreach (Yii::app()->log->routes as $route) {
if($route instanceof CWebLogRoute) {
$route->enabled = false; // disable any weblogroutes
}
}
Yii::app()->end();
}
Appreciate any help on this
i try.
change
'dataType' => 'jsonp' to 'dataType' => 'json'
and check json format
https://github.com/ivaynberg/select2/issues/920

dynamically adding text boxes in drupal form api

I want to have a add more button on clicking which i can add dynamically, textboxes in a drupal form api.. can someone help on this?
Thanks in advance
Take a look at Adding dynamic form elements using AHAH. It is a good guide to learn AHAH with Drupal's form API.
EDIT: For an example, install the Examples for Developers module, it has an AHAH example you can use to help you learn.
Here is an example how to solve this with Ajax in Drupal 7(If anyone want I can convert it also to Drupal 6 using AHAH(name before it became Ajax)).
<?php
function text_boxes_form($form, &$form_state)
{
$number = 0;
$addTextbox = false;
$form['text_lists'] = array
(
'#tree' => true,
'#theme' => 'my_list_theme',
'#prefix' => '<div id="wrapper">',
'#suffix' => '</div>',
);
if (array_key_exists('triggering_element', $form_state) &&
array_key_exists('#name', $form_state['triggering_element']) &&
$form_state['triggering_element']['#name'] == 'Add'
) {
$addTextbox = true;
}
if (array_key_exists('values', $form_state) && array_key_exists('text_lists', $form_state['values']))
{
foreach ($form_state['values']['text_lists'] as $element) {
$form['text_lists'][$number]['text'] = array(
'#type' => 'textfield',
);
$number++;
}
}
if ($addTextbox) {
$form['text_lists'][$number]['text'] = array(
'#type' => 'textfield',
);
}
$form['add_button'] = array(
'#type' => 'button',
'#name' => 'Add',
'#ajax' => array(
'callback' => 'ajax_add_textbox_callback',
'wrapper' => 'wrapper',
'method' => 'replace',
'effect' => 'fade',
),
'#value' => t('Add'),
);
return $form;
}
function ajax_add_textbox_callback($form, $form_state)
{
return $form['text_lists'];
}
function text_boxes_menu()
{
$items = array();
$items['text_boxes'] = array(
'title' => 'Text Boxes',
'description' => 'Text Boxes',
'page callback' => 'drupal_get_form',
'page arguments' => array('text_boxes_form'),
'access callback' => array(TRUE),
'type' => MENU_CALLBACK,
);
return $items;
}