diff --git a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php index cd3b5725b2b2aa7d108cdfe143951761527a664a..2e8008f2771fc90b2318c22b5412c15d4b858434 100644 --- a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php +++ b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php @@ -121,10 +121,10 @@ class HighchartsChartsRender implements ChartsRenderInterface { $yAxes = []; $yAxisTitle = new YaxisTitle(); $yAxisTitle->setText($options['yaxis_title']); - if (!empty($options['yaxis_min'])) { + if (is_numeric($options['yaxis_min'])) { $chartYaxis->min = $options['yaxis_min']; } - if (!empty($options['yaxis_max'])) { + if (is_numeric($options['yaxis_max'])) { $chartYaxis->max = $options['yaxis_max']; } @@ -197,6 +197,7 @@ class HighchartsChartsRender implements ChartsRenderInterface { $highchart->setChart($chart); $highchart->setTitle($chartTitle); $highchart->setAxisX($chartXaxis); + $highchart->setAxisY($chartYaxis); $highchart->setTooltip($chartTooltip); $highchart->setPlotOptions($plotOptions); $highchart->setCredits($chartCredits); diff --git a/modules/charts_highcharts/src/Plugin/chart/Highchart.php b/modules/charts_highcharts/src/Plugin/chart/Highchart.php index 718a6899320b1f5560f4acb2dff9eef1aa88d854..37b70b7de5e42ca84a61a738468f9f6e8e542c3e 100644 --- a/modules/charts_highcharts/src/Plugin/chart/Highchart.php +++ b/modules/charts_highcharts/src/Plugin/chart/Highchart.php @@ -82,7 +82,7 @@ class Highchart extends AbstractChart { // Set chart title. $chartTitle = new ChartTitle(); - if ((isset($options['title'])) && (!empty($options['title_position']))) { + if (isset($options['title'])) { $chartTitle->setText($options['title']); } @@ -97,11 +97,13 @@ class Highchart extends AbstractChart { } // Set title position. - if ($options['title_position'] == 'in') { - $chartTitle->setVerticalAlign('middle'); - } - else { - $chartTitle->setVerticalAlign('top'); + if (isset($options['title_position'])) { + if ($options['title_position'] == 'in') { + $chartTitle->setVerticalAlign('middle'); + } + else { + $chartTitle->setVerticalAlign('top'); + } } $chartXaxis = new Xaxis(); @@ -126,10 +128,10 @@ class Highchart extends AbstractChart { $yAxes = []; $yAxisTitle = new YaxisTitle(); $yAxisTitle->setText($options['yaxis_title']); - if (!empty($options['yaxis_min'])) { + if (is_numeric($options['yaxis_min'])) { $chartYaxis->min = $options['yaxis_min']; } - if (!empty($options['yaxis_max'])) { + if (is_numeric($options['yaxis_max'])) { $chartYaxis->max = $options['yaxis_max']; } @@ -160,20 +162,23 @@ class Highchart extends AbstractChart { $plotOptionsSeries = new PlotOptionsSeries(); $plotOptionsSeriesDataLabels = new PlotOptionsSeriesDataLabels(); // Set plot options if stacked chart. - if(!empty($options['grouping'])) { + if (!empty($options['grouping'])) { $plotOptions->setPlotSeries($plotOptionsStacking); $plotOptionsStacking->setDataLabels($plotOptionsSeriesDataLabels); - $plotOptionsSeriesDataLabels->setEnabled($options['data_labels']); } else { $plotOptions->setPlotSeries($plotOptionsSeries); $plotOptionsSeries->setDataLabels($plotOptionsSeriesDataLabels); + } + if (isset($options['data_labels'])) { $plotOptionsSeriesDataLabels->setEnabled($options['data_labels']); } // Set Tooltip. $chartTooltip = new Tooltip(); - $chartTooltip->setEnabled($options['tooltips']); + if (isset($options['tooltips'])) { + $chartTooltip->setEnabled($options['tooltips']); + } $chartCredits = new ChartCredits(); // Set charts legend. @@ -199,6 +204,7 @@ class Highchart extends AbstractChart { $highchart->setChart($chart); $highchart->setTitle($chartTitle); $highchart->setAxisX($chartXaxis); + $highchart->setAxisY($chartYaxis); $highchart->setTooltip($chartTooltip); $highchart->setPlotOptions($plotOptions); $highchart->setCredits($chartCredits); diff --git a/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php b/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php index 7095ac3547711a769e805b04f0d955a9c2d0f048..9deb147a6e5cf0843105ade5b532b4145d104c1a 100644 --- a/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php +++ b/modules/charts_highcharts/src/Settings/Highcharts/Highcharts.php @@ -10,13 +10,13 @@ class Highcharts implements \JsonSerializable { private $chart; private $title; private $xAxis; + private $yAxis; private $tooltip; private $plotOptions; private $legend; private $credits; private $innerSize = '%20'; private $series; - /* private $yAxis; */ /** * Get Chart. @@ -78,16 +78,25 @@ class Highcharts implements \JsonSerializable { $this->xAxis = $xAxis; } - /* - @return mixed - public function getYAxis() { - return $this->yAxis; - } - @param mixed $yAxis - public function setYAxis($yAxis) { - $this->yAxis = $yAxis; + /** + * Get Y Axis. + * + * @return \Drupal\charts_highcharts\Settings\Highcharts\Yaxis|null + * Y Axis. + */ + public function getAxisY() { + return $this->yAxis; } + + /** + * Set Y Axis. + * + * @param \Drupal\charts_highcharts\Settings\Highcharts\Yaxis $yAxis + * Y Axis. */ + public function setAxisY(Yaxis $yAxis) { + $this->yAxis = $yAxis; + } /** * Get Tooltip.