You are here

function _fusioncharts_charts_render in Charts 7

Implementation of hook_charts_render().

Its a Charts module hook. It transform the data into a HTML chart.

Parameters

&$data: Array. The

1 string reference to '_fusioncharts_charts_render'
fusioncharts_charts_info in fusioncharts/fusioncharts.hooks.inc
Implementation of hook_charts_info().

File

fusioncharts/fusioncharts.inc, line 86
@author Bruno Massa http://drupal.org/user/67164

Code

function _fusioncharts_charts_render(&$data) {

  // Convert the chat TYPE into the FusionCharts way.
  // Since its a requirement to build the chart on Google, if the value
  // was not found, return nothing and stop the execution.
  $options = array(
    'line2D' => 'MSLine.swf',
    'hbar2D' => 'MSBar2D.swf',
    'hbar3D' => 'MSBar3D.swf',
    'vbar2D' => 'MSColumn2D.swf',
    'vbar3D' => 'MSColumn3D.swf',
    'pie2D' => 'Pie2D.swf',
    'pie3D' => 'Pie3D.swf',
  );
  if (empty($options[$data['#type']])) {
    return t('This type is not possible using %chartplugin', array(
      '%chartplugin' => 'FusionCharts',
    ));
  }
  $file = file_create_url('fusioncharts') . '/' . $options[$data['#type']];

  // Convert the chat SIZE into the FusionCharts way.
  // Since its a requirement to build the chart on Google, if the value
  // was not found, return nothing and stop the execution.
  if (empty($data['#width']) or empty($data['#height'])) {
    return '';
  }
  $width = $data['#width'];
  $height = $data['#height'];
  $chart = array(
    'key' => 'chart',
    'value' => array(),
  );
  if ($message = _fusioncharts_chart($chart, $data)) {
    return $message;
  }
  $series = '_fusioncharts_series';
  if ($data['#type'] == 'pie2D' or $data['#type'] == 'pie3D') {
    $series = '_fusioncharts_series_single';
  }
  if ($message = $series($chart, $data)) {
    return $message;
  }
  $chart = '&dataXML=' . str_replace('"', "'", format_xml_elements(array(
    $chart,
  )));

  // Its the HTML tag to include the chart
  return <<<FUSIONCHARTS
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="{<span class="php-variable">$width</span>}" height="{<span class="php-variable">$height</span>}">
  <param name="allowScriptAccess" value="always" />
  <param name="movie" value="{<span class="php-variable">$file</span>}" />
  <param name="FlashVars" value="&chartWidth={<span class="php-variable">$width</span>}&chartHeight={<span class="php-variable">$height</span>}{<span class="php-variable">$chart</span>}" />
  <param name="quality" value="high" />
  <embed src="{<span class="php-variable">$file</span>}" flashVars="&chartWidth={<span class="php-variable">$width</span>}&chartHeight={<span class="php-variable">$height</span>}{<span class="php-variable">$chart</span>}" width="{<span class="php-variable">$width</span>}" height="{<span class="php-variable">$height</span>}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
FUSIONCHARTS;
}