diff --git a/readme.md b/readme.md index 1640e88..45993b5 100644 --- a/readme.md +++ b/readme.md @@ -131,7 +131,7 @@ $chart_options = [ ``` - `chart_title` (required) - just a text title that will be shown as legend; -- `chart_type` (required) - possible values: "line", "bar", "pie"; +- `chart_type` (required) - possible values: "line", "bar", "pie", "doughnut"; - `report_type` (required) - see above, can be `group_by_date`, `group_by_string` or `group_by_relationship`; - `model` (required) - name of Eloquent model, where to take the data from; - `name` (optional) - just a text title that will be shown as title, otherwise the legend is used; diff --git a/src/Classes/LaravelChart.php b/src/Classes/LaravelChart.php index f753f30..4cd32ff 100644 --- a/src/Classes/LaravelChart.php +++ b/src/Classes/LaravelChart.php @@ -256,7 +256,7 @@ private function validateOptions(array $options) 'group_by_field' => 'required|bail', 'group_by_period' => 'in:day,week,month,year|bail', 'aggregate_function' => 'in:count,sum,avg|bail', - 'chart_type' => 'required|in:line,bar,pie|bail', + 'chart_type' => 'required|in:line,bar,pie,doughnut|bail', 'filter_days' => 'integer', 'filter_period' => 'in:week,month,year', 'hidden' => 'boolean', @@ -314,7 +314,7 @@ public function renderJs() */ public function renderChartJsLibrary() { - return ''; + return ''; } /** diff --git a/src/views/javascript.blade.php b/src/views/javascript.blade.php index 28e4d66..ba3e4fb 100644 --- a/src/views/javascript.blade.php +++ b/src/views/javascript.blade.php @@ -35,7 +35,7 @@ @else borderColor: 'rgba({{ rand(0,255) }}, {{ rand(0,255) }}, {{ rand(0,255) }}, 0.2)', @endif - @elseif ($options['chart_type'] == 'pie') + @elseif ($options['chart_type'] == 'pie' || $options['chart_type'] == 'doughnut') backgroundColor: [ @foreach ($dataset['data'] as $group => $result) @if (isset($dataset['chart_color'][$group]) && $dataset['chart_color'][$group] != '') @@ -55,11 +55,26 @@ ] }, options: { + plugins: { + @if ($options['chart_type'] == 'pie' || $options['chart_type'] == 'doughnut') + labels: [ + { + render: 'percentage' + } + ] + @elseif ($options['chart_type'] == 'bar') + labels: [ + { + render: 'value' + } + ] + @endif + }, tooltips: { mode: 'point' }, height: '{{ $options['chart_height'] ?? "300px" }}', - @if ($options['chart_type'] != 'pie') + @if ($options['chart_type'] != 'pie' && $options['chart_type'] != 'doughnut') scales: { xAxes: [], yAxes: [{