function chart_views_plugin_style_chart::render in Google Chart Tools: Image Charts 6
Same name and namespace in other branches
- 7 chart_views/views/chart_views_plugin_style_chart.inc \chart_views_plugin_style_chart::render()
Define and display a chart from the grouped values.
File
- chart_views/
includes/ views/ chart_views_plugin_style_chart.inc, line 139 - Drupal Chart API Views Integration. @Based on the Charts module's Views integration
Class
- chart_views_plugin_style_chart
- Style plugin to render view as a chart.
Code
function render() {
// Get chart settings from options form.
// Get values from rows.
//drupal_set_message(dprint_r($this->view->field, TRUE));
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;
}
$data[] = $row->{$calc};
$label = strip_tags(theme_views_view_field($this->view, $this->view->field[$key], $row));
if ($this->options['values_legend']) {
$label .= ' ' . $row->{$calc};
}
if ($label != $last_label) {
$labels[] = $label;
$last_label = $label;
}
else {
$labels[] = '';
}
$data_colors[] = chart_unique_color($label);
}
}
}
}
$chart['#data'] = $data;
$chart['#labels'] = $labels;
$chart['#type'] = $this->options['type'];
$chart['#chart_id'] = $this->view->name . '-' . $this->display->id;
$chart['#size']['#width'] = $this->options['width'];
$chart['#size']['#height'] = $this->options['height'];
$chart['#data_colors'] = $data_colors;
//Return the rendered chart.
return chart_render($chart);
}