diff --git a/modules/charts_highcharts/js/charts_highcharts.js b/modules/charts_highcharts/js/charts_highcharts.js index 36629f82a8be4a4420ce0c6551df8db0e2cdfcf2..1b18ea9b8d409dd64a0d944c785824bdbd542a03 100644 --- a/modules/charts_highcharts/js/charts_highcharts.js +++ b/modules/charts_highcharts/js/charts_highcharts.js @@ -11,7 +11,36 @@ $('.charts-highchart').once().each(function () { if ($(this).attr('data-chart')) { var highcharts = $(this).attr('data-chart'); - $(this).highcharts(JSON.parse(highcharts)); + var hc = JSON.parse(highcharts); + if (hc.chart.type === 'pie') { + delete hc.plotOptions.bar; + hc.plotOptions.pie = { + allowPointSelect: true, + cursor: 'pointer', + showInLegend: true, + dataLabels: { + enabled: true, + format: '{point.y:,.0f}' + } + }; + + hc.legend.enabled = true; + hc.legend.labelFormatter = function () { + var legendIndex = this.index; + return this.series.chart.axes[0].categories[legendIndex]; + }; + + hc.tooltip.formatter = function () { + var sliceIndex = this.point.index; + var sliceName = this.series.chart.axes[0].categories[sliceIndex]; + return '' + sliceName + + ' : ' + this.y + ''; + }; + + console.log(hc); + } + + $(this).highcharts(hc); } }); } diff --git a/src/Form/ChartsConfigForm.php b/src/Form/ChartsConfigForm.php index 9e37207fe63e2849fd148244f318b6561a987568..3a9c0a96516109075f3450e74c9a09f966c0b065 100644 --- a/src/Form/ChartsConfigForm.php +++ b/src/Form/ChartsConfigForm.php @@ -131,6 +131,8 @@ class ChartsConfigForm extends ConfigFormBase { // Ensure all defaults are set. $options = array_merge($this->charts_default_settings(), $defaults); + $form['#attached']['library'][] = ['charts', 'charts.admin']; + // Get a list of available chart libraries. $charts_info = $this->charts_info(); $library_options = []; @@ -179,7 +181,7 @@ class ChartsConfigForm extends ConfigFormBase { // Set data attributes to identify special properties of different types. foreach ($chart_types as $chart_type => $chart_type_info) { - if (isset($chart_type_info['axis_inverted']) && $chart_type_info['axis_inverted']) { + if ($chart_type_info['axis_inverted']) { $form['type'][$chart_type]['#attributes']['data-axis-inverted'] = TRUE; } if ($chart_type_info['axis'] === ChartsInterface::CHARTS_SINGLE_AXIS) { @@ -483,10 +485,6 @@ class ChartsConfigForm extends ConfigFormBase { 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, 'stacking' => TRUE, ]; - $chart_types['donut'] = [ - 'label' => $this->t('Donut'), - 'axis' => ChartsInterface::CHARTS_SINGLE_AXIS, - ]; $chart_types['line'] = [ 'label' => $this->t('Line'), 'axis' => ChartsInterface::CHARTS_DUAL_AXIS, diff --git a/src/Plugin/views/display/ChartsPluginDisplayChart.php b/src/Plugin/views/display/ChartsPluginDisplayChart.php index 1eb65b3cc030d948a097395b3de335c194404ed0..db1869109e3b6b0c99eb5668550e59ac72d57e94 100644 --- a/src/Plugin/views/display/ChartsPluginDisplayChart.php +++ b/src/Plugin/views/display/ChartsPluginDisplayChart.php @@ -117,11 +117,7 @@ class ChartsPluginDisplayChart extends Attachment { } /** - * Perform any necessary changes to the form values prior to storage. - * There is no need for this function to actually store the data. - * - * @param $form - * @param FormStateInterface $form_state + * {@inheritdoc} */ public function submitOptionsForm(&$form, FormStateInterface $form_state) { // It is very important to call the parent function here: @@ -131,7 +127,7 @@ class ChartsPluginDisplayChart extends Attachment { case 'displays': $form_state->setValue($section, array_filter($form_state->getValue($section))); break; - + // @todo set isDefaulted to false by default. case 'inherit_arguments': case 'inherit_exposed_filters': case 'inherit_yaxis':