step1 : sites/all/modules/ofc_api/php-ofc-library/ofc_upload_image.php
Add following code:
// default path for the image to be stored //
- $default_path = '../tmp-upload-images/';
+if( ! $_GET['defaultPath'] ) {
+ $default_path = '../tmp-upload-images/';
+} else {
+ $default_path = $_GET['defaultPath'];
+}
step2 : display chart area
/*************** display chart using area start*************/
$chart = new open_flash_chart();
$title = new title( 'Future & Option Chart' );
$title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );
$chart->set_title( $title );
$area = new area();
$area->set_colour( '#5B56B6' );
$area->set_values( $call_buy );
$area->set_key( 'Call_Buy', 13 );
$area->on_show(new line_on_show($animation[0], $cascade[0], $delay[0]));
$chart->add_element( $area );
$call_write = new area();
$call_write->set_colour( '#800517' );
$call_write->set_values( $CallWrite );
$call_write->set_key( 'Call_Write', 13 );
$call_write->on_show(new line_on_show($animation[1], $cascade[1], $delay[1]));
$chart->add_element( $call_write );
$put_buy = new area();
$put_buy->set_colour( '#00FFFF' );
$put_buy->set_values( $putbuy );
$put_buy->set_key( 'Put_Buy', 13 );
$put_buy->on_show(new line_on_show($animation[2], $cascade[2], $delay[2]));
$chart->add_element( $put_buy );
$put_write = new area();
$put_write->set_colour( '#52D017' );
$put_write->set_values( $putwrite );
$put_write->set_key( 'Put_Write', 13 );
$put_write->on_show(new line_on_show($animation[3], $cascade[3], $delay[3]));
$chart->add_element( $put_write );
$future_buy = new area();
$future_buy->set_colour( '#8D38C9' );
$future_buy->set_values( $futureBuy );
$future_buy->set_key( 'Future_Buy', 13 );
$future_buy->on_show(new line_on_show($animation[4], $cascade[4], $delay[4]));
$chart->add_element( $future_buy );
$future_sell = new area();
$future_sell->set_colour( '#F778A1' );
$future_sell->set_values( $futureSell );
$future_sell->set_key( 'Future_sell', 13 );
$future_sell->on_show(new line_on_show($animation[5], $cascade[5], $delay[5]));
$chart->add_element( $future_sell );
// $average = new area();
// $average->set_colour( '#0E440E' );
// $average->set_values( $avg );
// $average->set_key( 'Resultant Profit', 13 );
// $average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
// $chart->add_element( $average );
$line_1_default_dot = new solid_dot();
$line_1_default_dot->size(2)->halo_size(2)->colour('#0E440E');
$average = new line();
$average->set_default_dot_style($line_1_default_dot);
$average->set_values( $avg );
$average->set_width( 1 );
$average->set_key( 'Resultant Profit', 13 );
$average->set_colour( '#0E440E' );
$average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
$chart->add_element( $average );
$x_labels = new x_axis_labels();
$x_labels->set_steps( 1 );
$x_labels->set_vertical();
$x_labels->set_colour( '#A2ACBA' );
$x_labels->set_labels( $current_market );
$x = new x_axis();
$x->set_colour( '#A2ACBA' );
$x->set_grid_colour( '#D7E4A3' );
$x->set_offset( false );
$x->set_steps(1);
// Add the X Axis Labels to the X Axis
$x->set_labels( $x_labels );
$chart->set_x_axis( $x );
$x_legend = new x_legend( $min . ' to ' . $max );
$x_legend->set_style( '{font-size: 20px; color: #778877}' );
$chart->set_x_legend( $x_legend );
//
// remove this when the Y Axis is smarter
//
$y = new y_axis();
$y->set_range( $ymin, $ymax, $y_diff );
$chart->add_y_axis( $y );
step3: here jquery call to get unique id of swf
/************** display chart using area end ***************/
$displayChart = array();
$displayChart['resultant'] = $resulant_lossprofit;
$chartId = ofc_api_unique_id();
$displayChart['chart_id'] = $chartId ;
$displayChart['chart'] = fno_chart_api_render($chart, 800, 400, array(), $chartId);
//here unique chart id set
drupal_add_js("var open_chart_id = '{$chartId}'", 'inline');
//on particular button click function this image stored in default path
$js6 = "jQuery(document).ready(function(){
jQuery('#chart-pdf1').bind('click', function(){
var url = 'http://192.168.2.74/stock_adv/sites/all/modules/ofc_api/php-ofc-library/ofc_upload_image.php'; //call ofc_upload_image.php
url += '?name={$chartId}.png'; //append image name
url += '&defaultPath=' + '/home/ajay/public_html/stock_adv/sites/default/files/'; //default path where image stored
swfobject.getObjectById(open_chart_id).post_image(url,true, false ); //ofc method to get image stored in default path
});
});";
drupal_add_js($js6, 'inline');
return $displayChart;
}
step 4: there chart api render function call to display swf object
function fno_chart_api_render($chart = 'ofc_api_sample', $width = 800, $height = 400, $params = array(), $id=false ) {
$swf = url(drupal_get_path('module', 'ofc_api') . '/open-flash-chart.swf');
if ( !$id ) {
$id = ofc_api_unique_id();
}
// Call hook_ofc_api_data() to get all function names that will return chart data
$charts = module_invoke_all('ofc_api_data');
// $chart contains a function name
if (in_array($chart, $charts, true) && function_exists($chart)) {
$method = 'data-file';
$source = url('ofc_api/data/' . $chart);
}
// $chart is a chart object
elseif (is_object($chart) && isset($chart->elements)) {
$method = 'get-data';
$source = $id;
$json = drupal_to_js(json_encode($chart));
}
// $chart contains the JSON string
elseif (is_string($chart) && is_object(json_decode($chart))) {
$method = 'get-data';
$source = $id;
$json = drupal_to_js($chart);
}
// $chart is in unknown format
else {
$method = 'data-file';
$source = url('ofc_api/data/not-found');
}
$data = array(
'@swf' => $swf,
'@id' => $id,
'@width' => check_plain($width),
'@height' => check_plain($height),
'@method' => $method,
'@source' => $source,
'@json' => $json,
);
return ofc_api_render_html($data, $params);
}
Add following code:
// default path for the image to be stored //
- $default_path = '../tmp-upload-images/';
+if( ! $_GET['defaultPath'] ) {
+ $default_path = '../tmp-upload-images/';
+} else {
+ $default_path = $_GET['defaultPath'];
+}
step2 : display chart area
/*************** display chart using area start*************/
$chart = new open_flash_chart();
$title = new title( 'Future & Option Chart' );
$title->set_style( "{font-size: 20px; color: #A2ACBA; text-align: center;}" );
$chart->set_title( $title );
$area = new area();
$area->set_colour( '#5B56B6' );
$area->set_values( $call_buy );
$area->set_key( 'Call_Buy', 13 );
$area->on_show(new line_on_show($animation[0], $cascade[0], $delay[0]));
$chart->add_element( $area );
$call_write = new area();
$call_write->set_colour( '#800517' );
$call_write->set_values( $CallWrite );
$call_write->set_key( 'Call_Write', 13 );
$call_write->on_show(new line_on_show($animation[1], $cascade[1], $delay[1]));
$chart->add_element( $call_write );
$put_buy = new area();
$put_buy->set_colour( '#00FFFF' );
$put_buy->set_values( $putbuy );
$put_buy->set_key( 'Put_Buy', 13 );
$put_buy->on_show(new line_on_show($animation[2], $cascade[2], $delay[2]));
$chart->add_element( $put_buy );
$put_write = new area();
$put_write->set_colour( '#52D017' );
$put_write->set_values( $putwrite );
$put_write->set_key( 'Put_Write', 13 );
$put_write->on_show(new line_on_show($animation[3], $cascade[3], $delay[3]));
$chart->add_element( $put_write );
$future_buy = new area();
$future_buy->set_colour( '#8D38C9' );
$future_buy->set_values( $futureBuy );
$future_buy->set_key( 'Future_Buy', 13 );
$future_buy->on_show(new line_on_show($animation[4], $cascade[4], $delay[4]));
$chart->add_element( $future_buy );
$future_sell = new area();
$future_sell->set_colour( '#F778A1' );
$future_sell->set_values( $futureSell );
$future_sell->set_key( 'Future_sell', 13 );
$future_sell->on_show(new line_on_show($animation[5], $cascade[5], $delay[5]));
$chart->add_element( $future_sell );
// $average = new area();
// $average->set_colour( '#0E440E' );
// $average->set_values( $avg );
// $average->set_key( 'Resultant Profit', 13 );
// $average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
// $chart->add_element( $average );
$line_1_default_dot = new solid_dot();
$line_1_default_dot->size(2)->halo_size(2)->colour('#0E440E');
$average = new line();
$average->set_default_dot_style($line_1_default_dot);
$average->set_values( $avg );
$average->set_width( 1 );
$average->set_key( 'Resultant Profit', 13 );
$average->set_colour( '#0E440E' );
$average->on_show(new line_on_show($animation[6], $cascade[6], $delay[6]));
$chart->add_element( $average );
$x_labels = new x_axis_labels();
$x_labels->set_steps( 1 );
$x_labels->set_vertical();
$x_labels->set_colour( '#A2ACBA' );
$x_labels->set_labels( $current_market );
$x = new x_axis();
$x->set_colour( '#A2ACBA' );
$x->set_grid_colour( '#D7E4A3' );
$x->set_offset( false );
$x->set_steps(1);
// Add the X Axis Labels to the X Axis
$x->set_labels( $x_labels );
$chart->set_x_axis( $x );
$x_legend = new x_legend( $min . ' to ' . $max );
$x_legend->set_style( '{font-size: 20px; color: #778877}' );
$chart->set_x_legend( $x_legend );
//
// remove this when the Y Axis is smarter
//
$y = new y_axis();
$y->set_range( $ymin, $ymax, $y_diff );
$chart->add_y_axis( $y );
step3: here jquery call to get unique id of swf
/************** display chart using area end ***************/
$displayChart = array();
$displayChart['resultant'] = $resulant_lossprofit;
$chartId = ofc_api_unique_id();
$displayChart['chart_id'] = $chartId ;
$displayChart['chart'] = fno_chart_api_render($chart, 800, 400, array(), $chartId);
//here unique chart id set
drupal_add_js("var open_chart_id = '{$chartId}'", 'inline');
//on particular button click function this image stored in default path
$js6 = "jQuery(document).ready(function(){
jQuery('#chart-pdf1').bind('click', function(){
var url = 'http://192.168.2.74/stock_adv/sites/all/modules/ofc_api/php-ofc-library/ofc_upload_image.php'; //call ofc_upload_image.php
url += '?name={$chartId}.png'; //append image name
url += '&defaultPath=' + '/home/ajay/public_html/stock_adv/sites/default/files/'; //default path where image stored
swfobject.getObjectById(open_chart_id).post_image(url,true, false ); //ofc method to get image stored in default path
});
});";
drupal_add_js($js6, 'inline');
return $displayChart;
}
step 4: there chart api render function call to display swf object
function fno_chart_api_render($chart = 'ofc_api_sample', $width = 800, $height = 400, $params = array(), $id=false ) {
$swf = url(drupal_get_path('module', 'ofc_api') . '/open-flash-chart.swf');
if ( !$id ) {
$id = ofc_api_unique_id();
}
// Call hook_ofc_api_data() to get all function names that will return chart data
$charts = module_invoke_all('ofc_api_data');
// $chart contains a function name
if (in_array($chart, $charts, true) && function_exists($chart)) {
$method = 'data-file';
$source = url('ofc_api/data/' . $chart);
}
// $chart is a chart object
elseif (is_object($chart) && isset($chart->elements)) {
$method = 'get-data';
$source = $id;
$json = drupal_to_js(json_encode($chart));
}
// $chart contains the JSON string
elseif (is_string($chart) && is_object(json_decode($chart))) {
$method = 'get-data';
$source = $id;
$json = drupal_to_js($chart);
}
// $chart is in unknown format
else {
$method = 'data-file';
$source = url('ofc_api/data/not-found');
}
$data = array(
'@swf' => $swf,
'@id' => $id,
'@width' => check_plain($width),
'@height' => check_plain($height),
'@method' => $method,
'@source' => $source,
'@json' => $json,
);
return ofc_api_render_html($data, $params);
}
No comments:
Post a Comment