function chart_views_plugin_style_chart::render in Google Chart Tools: Image Charts 7
Same name and namespace in other branches
- 6 chart_views/includes/views/chart_views_plugin_style_chart.inc \chart_views_plugin_style_chart::render()
Render the display in this style.
Overrides views_plugin_style::render
File
- chart_views/
views/ chart_views_plugin_style_chart.inc, line 132 - Contains the chart display plugin.
Class
- chart_views_plugin_style_chart
- The plugin that handles the chart style.
Code
function render() {
$charts = array();
$sets = $this
->render_grouping($this->view->result, $this->options['grouping']);
$one = count($sets) == 1;
$set = 0;
foreach ($sets as $title => $records) {
$chart = array(
'#theme' => 'chart',
'#chart_id' => drupal_clean_css_identifier($this->view->name . '-' . $this->display->id . '-' . $set++),
'#type' => $this->options['type'],
// If only one set then use the view title, otherwise if the set has a
// title then set it as the chart title.
'#title' => $one ? $this->view->human_name : $title,
'#size' => array(
'#width' => $this->options['width'],
'#height' => $this->options['height'],
),
'#adjust_resolution' => TRUE,
'#data' => array(),
'#labels' => array(),
'#data_colors' => array(),
'#shape_markers' => array(),
);
foreach ($records as $row_index => $row) {
foreach ($this->view->field as $key => $field) {
if (!$field->options['exclude']) {
$field_value = $field
->get_value($row);
$field_value = isset($field_value[0]['value']) ? $field_value[0]['value'] : 0;
// this would be nicer in 1 line.
$chart['#data'][] = $field_value;
$chart['#labels'][] = $field->options['label'] . ($this->options['label_append_value'] ? ': ' . $field_value : '');
// @TODO Provide a way to change format.
$chart['#data_colors'][] = chart_unique_color($key, $this->options['color_scheme']);
}
}
}
$series = 0;
foreach ($this->view->field as $key => $field) {
if (!$field->options['exclude']) {
if ($this->options['data_markers']) {
$chart['#shape_markers'][] = array(
'#marker_type' => 'N*' . $this->options['data_markers_number_type'] . $this->options['data_markers_decimal_places'] . '*',
'#color' => '000000',
'#series_index' => $series,
'#opt_which_points' => -1,
'#size' => 11,
'#opt_z_order' => '',
'#opt_placement' => $this->options['data_markers_placement'],
);
$series++;
}
}
}
// Allow modules to alter the chart based on views context.
drupal_alter('chart_views', $chart, $this->view->name, $this->display->id);
// Since view expects string output we can't save render array for later.
$charts[$chart['#chart_id']] = drupal_render($chart);
}
return implode($charts);
}