/** * Build The Pie Gharph. * * @param array $params assoc array of name/value pairs * * @return object $chart object of open flash chart. * @static */ static function &pieChart(&$params) { $chart = null; if (empty($params)) { return $chart; } $allValues = CRM_Utils_Array::value('values', $params); if (!is_array($allValues) || empty($allValues)) { return $chart; } // get the required data. $values = array(); foreach ($allValues as $label => $value) { $values[] = new pie_value((double) $value, $label); } $graphTitle = CRM_Utils_Array::value('legend', $params) ? $params['legend'] : ts('Pie Chart'); //get the currency. require_once 'CRM/Utils/Money.php'; $config = CRM_Core_Config::singleton(); $symbol = $config->defaultCurrencySymbol; $pie = new pie(); $pie->radius(100); // call user define function to handle on click event. if ($onClickFunName = CRM_Utils_Array::value('on_click_fun_name', $params)) { $pie->on_click($onClickFunName); } $pie->set_start_angle(35); $pie->add_animation(new pie_fade()); $pie->add_animation(new pie_bounce(2)); // set the tooltip. $tooltip = CRM_Utils_Array::value('tip', $params, "Amount is {$symbol} #val# of {$symbol} #total# <br>#percent#"); $pie->set_tooltip($tooltip); // set colours. $pie->set_colours(self::$_colours); $pie->set_values($values); //create chart. $chart = new open_flash_chart(); // create chart title obj. $title = new title($graphTitle); $chart->set_title($title); $chart->add_element($pie); $chart->x_axis = null; return $chart; }
if(num_rows($result) >= 1) { while ($line = fetch_array($result)) { $hosts[] = $line['host']; $pievalues[] = new pie_value(intval($line['count']), $line['host']); } } // Generate random pie colors for($i = 0; $i<=count($pievalues) ; $i++) { $colors[] = '#'.random_hex_color(); // 09B826 } $ctype->set_alpha(0.5); $ctype->add_animation( new pie_fade() ); $ctype->add_animation( new pie_bounce(5) ); // $ctype->start_angle( 270 ) $ctype->start_angle( 0 ); $ctype->set_tooltip( "#label#<br>#val# of #total#<br>#percent# of top $limit hosts" ); $ctype->radius(80); $ctype->set_colours( $colors ); $ctype->set_values( $pievalues ); $chart = new open_flash_chart(); // $chart->set_title( $title ); $chart->add_element( $ctype ); echo $chart->toPrettyString(); } // ------------------------------------------------------ // END Chart Generation // ------------------------------------------------------ ?>
function report_chart($data) { $title = new title("Availability Report "); $pie = new pie(); $pie->set_alpha(0.9); $pie->radius(90); //$pie->start_angle(100); $pie->add_animation(new pie_fade()); $pie->set_tooltip('#label#: #percent#<br>#val# of #total#<br>'); $status_colors = array(free => '#77CC6D', assigned => '#FF0000', reserved => '#6D86CC', free2 => '#77CC6D', assigned2 => '#FF0000', reserved2 => '#6D86CC'); $status_name = array(free => 'FREE', assigned => 'ASSIGNED', reserved => 'RESERVED', free2 => 'FREE', assigned2 => 'ASSIGNED', reserved2 => 'RESERVED'); $col = array(); $d = array(); foreach ($data as $name => $value) { if ($value > 0) { $d[] = new pie_value($value * 1, "{$status_name[$name]}"); array_push($col, $status_colors[$name]); } } $pie->set_values($d); $pie->set_colours($col); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($pie); $chart->x_axis = null; $chart->set_bg_colour('#202020'); $title->set_style("{font-size: 16px; font-family: Times New Roman; font-weight: bold; color: #000; text-align: center;}"); $chart->set_bg_colour('#FFFFFF'); $chart->set_title($title); // This is the VIEW section: // Should print this first. // $heading = "\n <script type='text/javascript'>\n \n var data = " . $chart->toPrettyString() . "\n\n </script>\n\n\n <script type=\"text/javascript\">\n \n OFC = {};\n \n OFC.jquery = {\n name: 'jQuery',\n version: function(src) { return \$('#'+ src)[0].get_version() },\n rasterize: function (src, dst) { \$('#'+ dst).replaceWith(OFC.jquery.image(src)) },\n image: function(src) { return \"<img src='data:image/png;base64,\" + \$('#'+src)[0].get_img_binary() + \"' />\"},\n popup: function(src) {\n var img_win = window.open('', 'Charts: Export as Image')\n with(img_win.document) {\n write('<html><head><title>Charts: Export as Image<\\/title><\\/head><body>' + OFC.jquery.image(src) + '<\\/body><\\/html>') }\n // stop the 'loading...' message\n img_win.document.close();\n }\n }\n \n // Using_ an object as namespaces is JS Best Practice. I like the Control.XXX style.\n //if (!Control) {var Control = {}}\n //if (typeof(Control == \"undefined\")) {var Control = {}}\n if (typeof(Control == \"undefined\")) {var Control = {OFC: OFC.jquery}}\n \n \n // By default, right-clicking on OFC and choosing \"save image locally\" calls this function.\n // You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)\n // function save_image() { alert(1); Control.OFC.popup('my_chart') }\n function save_image() { alert(\"Your image will be displayed in a new window\"); OFC.jquery.popup('my_chart') }\n </script>\n <div id='my_chart' style='float:left; margin-left:28px;'></div>\n "; return $heading; }
function report_chart($data) { // Chart // // This is the MODEL section: // include 'open-flash-chart/php-ofc-library/open-flash-chart.php'; $title = new title("Availability Report "); $pie = new pie(); $pie->set_alpha(0.9); $pie->radius(90); //$pie->start_angle(100); $pie->add_animation(new pie_fade()); $pie->set_tooltip('#label#: #percent#<br>#val# of #total#<br>'); $status_colors = array(ok => '#77CC6D', critical => '#FF0000', warning => '#FFD40F', unknown => '#6D86CC', no_data => '#848484'); $status_name = array(ok => 'Ok', critical => 'Critical', warning => 'Warning', unknown => 'Unknown', no_data => 'No Data'); $col = array(); $d = array(); foreach ($data as $name => $value) { if ($value > 0) { $d[] = new pie_value($value * 1, "{$status_name[$name]}"); array_push($col, $status_colors[$name]); } } $pie->set_values($d); $pie->set_colours($col); $chart = new open_flash_chart(); $chart->set_title($title); $chart->add_element($pie); $chart->x_axis = null; $chart->set_bg_colour('#202020'); $title->set_style("{font-size: 16px; font-family: Times New Roman; font-weight: bold; color: #000; text-align: center;}"); $chart->set_bg_colour('#FFFFFF'); $chart->set_title($title); // This is the VIEW section: // Should print this first. // $heading = "\n <script type='text/javascript' src='open-flash-chart/js/json/json2.js'></script>\n <script type='text/javascript' src='open-flash-chart/js/swfobject.js'></script>\n <script type='text/javascript'>\n swfobject.embedSWF('open-flash-chart/open-flash-chart.swf', 'my_chart', '300', '300', '9.0.0');\n </script>\n\n <script type='text/javascript'>\n\n function open_flash_chart_data() {\n return JSON.stringify(data);\n }\n\n function findSWF(movieName) {\n if (navigator.appName.indexOf('Microsoft')!= -1) {\n return window[movieName];\n } else {\n return document[movieName];\n }\n }\n \n var data = " . $chart->toPrettyString() . "\n\n </script>\n\n\n <script type=\"text/javascript\">\n \n OFC = {};\n \n OFC.jquery = {\n name: 'jQuery',\n version: function(src) { return \$('#'+ src)[0].get_version() },\n rasterize: function (src, dst) { \$('#'+ dst).replaceWith(OFC.jquery.image(src)) },\n image: function(src) { return \"<img src='data:image/png;base64,\" + \$('#'+src)[0].get_img_binary() + \"' />\"},\n popup: function(src) {\n var img_win = window.open('', 'Charts: Export as Image')\n with(img_win.document) {\n write('<html><head><title>Charts: Export as Image<\\/title><\\/head><body>' + OFC.jquery.image(src) + '<\\/body><\\/html>') }\n // stop the 'loading...' message\n img_win.document.close();\n }\n }\n \n // Using_ an object as namespaces is JS Best Practice. I like the Control.XXX style.\n //if (!Control) {var Control = {}}\n //if (typeof(Control == \"undefined\")) {var Control = {}}\n if (typeof(Control == \"undefined\")) {var Control = {OFC: OFC.jquery}}\n \n \n // By default, right-clicking on OFC and choosing \"save image locally\" calls this function.\n // You are free to change the code in OFC and call my wrapper (Control.OFC.your_favorite_save_method)\n // function save_image() { alert(1); Control.OFC.popup('my_chart') }\n function save_image() { alert(\"Your image will be displayed in a new window\"); OFC.jquery.popup('my_chart') }\n </script>\n <div id='my_chart' style='float:left; margin-left:28px;'></div>\n "; return $heading; }
$xml = simplexml_load_file('http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=617a87a0e61087dc75d2a9fee2984ca5&artist=' . urlencode($artist) . '&album=' . urlencode($album)); foreach ($xml->xpath("//image[@size='extralarge']") as $artistImg) { echo $artistImg; } } if ($hasData == true) { include 'OFC/php-ofc-library/open-flash-chart.php'; //Defaults $toolTip = '#val# of #total#<br>#percent# of 100%'; $toolTipLabel = '#label#<br>#val# of #total#<br>#percent# of 100%'; //Pie 1 $title1 = new title("Top Artisti"); $pie1 = new pie(); $pie1->set_alpha(0.6); $pie1->add_animation(new pie_bounce(8)); $pie1->radius(100); $pie1->add_animation(new pie_fade()); $pie1->set_tooltip($toolTip); $pie1->set_colours(array('#D544A2', '#9408E0', '#E25374', '#269C16', '#9F0946', '#EC7E64', '#8F4F64', '#0AD5A5', '#F957BD', '#F4C377', '#0CEBC5', '#CCDE8B', '#F7FB8C', '#7CBF0C', '#799756', '#D5FFA2')); //Pie 2 $title2 = new title("Top Melodii"); $pie2 = new pie(); $pie2->set_alpha(0.6); $pie2->add_animation(new pie_bounce(8)); //$pie2->radius(100); $pie2->add_animation(new pie_fade()); $pie2->set_tooltip($toolTip); $pie2->set_colours(array('#D544A2', '#9408E0', '#E25374', '#269C16', '#9F0946', '#EC7E64', '#8F4F64', '#0AD5A5', '#F957BD', '#F4C377', '#0CEBC5', '#CCDE8B', '#F7FB8C', '#7CBF0C', '#799756', '#D5FFA2')); //Pie 3 $title3 = new title("Top Albume"); $pie3 = new pie();