Custom charts

dcat-admin 1.5 has removed all chart components, if you want to add a chart component to your page, you can refer to the following procedure

To use chartjs as an example, first download chartjs and put it in the public directory, for example, in public/vendor/chartjs.

Then include the component in `app/Admin/bootstrap.php’.

  1. use Dcat\Admin\Facades\Admin;
  2. Admin::js('/vendor/chartjs/dist/Chart.min.js');

New view file resources/views/admin/charts/bar.blade.php

  1. <canvas id="myChart" width="400" height="400"></canvas>
  2. <script>
  3. $(function () {
  4. var ctx = document.getElementById("myChart").getContext('2d');
  5. var myChart = new Chart(ctx, {
  6. type: 'bar',
  7. data: {
  8. labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
  9. datasets: [{
  10. label: '# of Votes',
  11. data: [12, 19, 3, 5, 2, 3],
  12. backgroundColor: [
  13. 'rgba(255, 99, 132, 0.2)',
  14. 'rgba(54, 162, 235, 0.2)',
  15. 'rgba(255, 206, 86, 0.2)',
  16. 'rgba(75, 192, 192, 0.2)',
  17. 'rgba(153, 102, 255, 0.2)',
  18. 'rgba(255, 159, 64, 0.2)'
  19. ],
  20. borderColor: [
  21. 'rgba(255,99,132,1)',
  22. 'rgba(54, 162, 235, 1)',
  23. 'rgba(255, 206, 86, 1)',
  24. 'rgba(75, 192, 192, 1)',
  25. 'rgba(153, 102, 255, 1)',
  26. 'rgba(255, 159, 64, 1)'
  27. ],
  28. borderWidth: 1
  29. }]
  30. },
  31. options: {
  32. scales: {
  33. yAxes: [{
  34. ticks: {
  35. beginAtZero:true
  36. }
  37. }]
  38. }
  39. }
  40. });
  41. });
  42. </script>

You can then include this chart view anywhere on the page:

  1. public function index()
  2. {
  3. return Admin::content(function (Content $content) {
  4. $content->header('chart');
  5. $content->description('.....');
  6. $content->body(view('admin.charts.bar'));
  7. });
  8. }

Any chart library can be introduced in the above way, see view layout for multi-chart page layout