当我在仪表板上创建图表时,它运行正常。但是当我转到另一个页面(如帖子页面)之后,则发生了此图表错误。我该如何解决。我在所有页面中都使用了该页脚页面。此页脚在其他页面上显示错误。
Undefined variable: chart (View: C:\wamp64\www\AdBlog\resources\views\admin\layouts\footer.blade.php)
这是我所有管理页面的页脚页面
<footer class="main-footer">
<div class="pull-right hidden-xs">
<b>Version</b> 2.3.8
</div>
<strong>Copyright © 2019-{{ Carbon\carbon::now()->year }} <a href="http://facebook.com">NS Tech</a>.</strong> All rights
reserved.
<script src="{{ asset('admin/plugins/jQuery/jquery-2.2.3.min.js') }}"></script>
<!-- jQuery UI 1.11.4 -->
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
$.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.6 -->
<script src="{{ asset('admin/bootstrap/js/bootstrap.min.js') }}"></script>
<!-- Morris.js charts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="{{ asset('admin/plugins/morris/morris.min.js') }}"></script>
<!-- Sparkline -->
<script src="{{ asset('admin/plugins/sparkline/jquery.sparkline.min.js') }}"></script>
<!-- jvectormap -->
<script src="{{ asset('admin/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js') }}"></script>
<script src="{{ asset('admin/plugins/jvectormap/jquery-jvectormap-world-mill-en.js') }}"></script>
<!-- jQuery Knob Chart -->
<script src="{{ asset('admin/plugins/knob/jquery.knob.js') }}"></script>
<!-- daterangepicker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="{{ asset('admin/plugins/daterangepicker/daterangepicker.js') }}"></script>
<!-- datepicker -->
<script src="{{ asset('admin/plugins/datepicker/bootstrap-datepicker.js') }}"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="{{ asset('admin/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js') }}"></script>
<!-- Slimscroll -->
<script src="{{ asset('admin/plugins/slimScroll/jquery.slimscroll.min.js') }}"></script>
<!-- FastClick -->
<script src="{{ asset('admin/plugins/fastclick/fastclick.js') }}"></script>
<!-- AdminLTE App -->
<script src="{{ asset('admin/dist/js/app.min.js') }}"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="{{ asset('admin/dist/js/pages/dashboard.js') }}"></script>
<!-- AdminLTE for demo purposes -->
<script src="{{ asset('admin/dist/js/demo.js') }}"></script>
<!--Chart js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js" charset="utf-8"></script>
{!! $chart->script() !!}
{!! $linechart->script() !!}
@section('footerSection')
@show
</footer>
这是我的chart.js控制器页面
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Model\user\User;
use App\Model\user\category;
use App\Model\user\post;
use App\Model\user\tag;
use Illuminate\Http\Request;
use App\Charts\ViewsChart;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth:admin');
}
public function index()
{
$userCount = User::count();
$publishedPostsCount = post::where('created_at', '!=', null)->count();
$publishedCategoriesCount = tag::where('created_at', '!=', null)->count();
$publishedTagsCount = category::where('created_at', '!=', null)->count();
//for bar chart
$chart = new ViewsChart;
$chart->labels(['tags', 'category', 'posts', 'users']);
$dataset = $chart->dataset('Number of Records', 'bar', [$publishedTagsCount, $publishedCategoriesCount, $publishedPostsCount, $userCount]);
$dataset->backgroundColor(collect(['#7158e2','#3ae374', '#ff3838', '#7158e2']));
$dataset->color(collect(['#7d5fff','#32ff7e', '#ff4d4d', '#7158e2']));
//for doughnut chart1
$linechart = new ViewsChart;
$linechart->labels(['tags', 'category', 'posts', 'users']);
$dataset = $linechart->dataset('Number of Records', 'doughnut', [$publishedTagsCount, $publishedCategoriesCount, $publishedPostsCount, $userCount]);
$dataset->backgroundColor(collect(['#ff6384','#36a2eb', '#cc65fe', '#ffce56']));
$dataset->color(collect(['#7d5fff','#32ff7e', '#ff4d4d', '#7158e2']));
return view('admin.home')->with([
'user_count' => $userCount,
'published_post_count' => $publishedPostsCount,
'published_category_count' => $publishedCategoriesCount,
'published_Tag_count' => $publishedTagsCount,
'chart' => $chart,
'linechart' => $linechart
]);
}
}