You are here

function charts_plugin_style_chart::render in Charts 7

Same name and namespace in other branches
  1. 6 views/charts_plugin_style_chart.inc \charts_plugin_style_chart::render()
  2. 7.2 views/charts_plugin_style_chart.inc \charts_plugin_style_chart::render()

Define and display a chart from the grouped values.

Overrides views_plugin_style::render

File

views/charts_plugin_style_chart.inc, line 144
Contains the chart style plugin. @author Bruno Massa http://drupal.org/user/67164 @author Karen Stevenson http://drupal.org/user/45874

Class

charts_plugin_style_chart
Style plugin to render view as a chart.

Code

function render() {

  // Get chart settings from options form.
  $chart = $this->options['charts'];

  // Get values from rows.
  foreach ($this
    ->calc_fields() as $calc) {
    foreach ($this->view->result as $row) {
      foreach ($this->view->field as $key => $field) {
        if ($key == $this->options['aggregation_field']) {
          $legend_field = array_key_exists($calc, $this->view->field) ? $this->view->field[$calc] : NULL;
          $legend = !empty($legend_field->options['label']) ? $legend_field->options['label'] : NULL;
          if ($this->options['show_legend']) {
            $data[$calc]['#legend'] = $legend;
          }
          $value['#label'] = strip_tags(theme_views_view_field($this->view, $this->view->field[$key], $row));
          if ($this->options['show_sums']) {
            $value['#label'] .= ' (' . $row->{$calc} . ')';
          }
          $value['#value'] = $row->{$calc};
          $chart[$calc][] = $value;
        }
      }
    }
  }

  // Print the chart.
  return charts_chart($chart);
}