FlotPie.php in Flot 8
File
flot_views_pie/src/Plugin/views/style/FlotPie.php
View source
<?php
namespace Drupal\flot_views_pie\Plugin\views\style;
use Drupal\core\form\FormStateInterface;
use Drupal\views\Plugin\views\style\StylePluginBase;
class FlotPie extends StylePluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['labels'] = [
'default' => '',
];
$options['values'] = [
'default' => '',
];
$options['pie_or_bar'] = [
'default' => 'pie',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$field_names = $this->displayHandler
->getFieldLabels();
$form['labels'] = [
'#title' => $this
->t('The field that contains the chart labels'),
'#type' => 'select',
'#options' => $field_names,
'#default_value' => $this->options['labels'],
];
$form['values'] = [
'#title' => $this
->t('The field that contains the chart data'),
'#type' => 'select',
'#options' => $field_names,
'#default_value' => $this->options['values'],
];
$form['pie_or_bar'] = [
'#type' => 'radios',
'#title' => $this
->t('Chart Type'),
'#options' => array(
'pie' => $this
->t('Pie Chart'),
'bar' => $this
->t('Bar Chart'),
),
'#default_value' => $this->options['pie_or_bar'],
'#description' => $this
->t('Should the categorical data be rendered in a pue chart or bar chart?'),
];
}
}
Classes
Name |
Description |
FlotPie |
Style plugin to render a list of numbers as a pie chart. |