Laravel chart not loading - laravel

i am creating a laravel project with chart. i went though the documentation but this is site when i did https://charts.erik.cat/. but i ran into the error with when i load the into the dashboard Undefined variable $chart
what i tried so far i attached below please check.please give me the solution for correct this
SummaryChat.php
<?php
namespace App\Charts;
use ConsoleTVs\Charts\Classes\Chartjs\Chart;
class SummaryChart extends Chart
{
public function __construct()
{
parent::__construct();
}
}
ChartController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Charts\SummaryChart;
class ChartController extends Controller
{
public function chartLine()
{
$chart = new SummaryChart;
$chart->labels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])->load($api);
return view('admin.dashboard', compact('chart'));
}
}
app.blade.php
this page under the app.js i yield the chart js look like this.because i need to load js only one page which is dashboard only.
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>
#yield('js')
Dashboard.blade.php
<div class="row">
<div class="col-md-9">
<div id="app" style="height: 400px;">
{!! $chart->container() !!}
</div>
</div>
</div>
this under the #endsection i attached the js files based on the chat loading.
#endsection
#section('js')
<script src="https://unpkg.com/vue"></script>
<script>
var app = new Vue({
el: '#app',
});
</script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/echarts/4.0.2/echarts-en.min.js charset=utf-8></script>
#endsection

As far as I am understanding from your code, you are initializing
new SampleChart
But you have not imported it yet. Make sure you are importing that by
use App\Charts\SampleChart;
Here is the official link to the laravel chart that I have found:
https://charts.erik.cat/create_charts.html#initiate-a-chart?
And also in the JS section you can not use $ sign in script. It is php variable sign which you are trying to use in the javascript.

Related

laravel8 input typeahead autocomplete wont work when include #extends('layouts.app')

I have been finding ways to get this work but no luck.
i want to use typeahead autocomplete function.
main scripts on my app.blade
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
{{-- <script src="https://unpkg.com/element-plus/lib/index.full.js"></script>--}}
then i have this script on my search blade
#extends('layouts.app')
#section('content')
<input class="typeahead form-control" name="query" type="search" placeholder="search" autocomplete="off"> </input>
<script type="text/javascript">
var path = "{{ route('autocomplete') }}";
$('input.typeahead').typeahead({
source: function (query, process) {
return $.get(path, { query: query }, function (data) {
return process(data);
});
}
});
</script>
#endsection
and then my search controller
public function autocomplete(Request $request)
{
$search_text = $request->input('query');
$data = Skills::select("name")
->where("name","LIKE","%{$search_text}%")
->get();
return response()->json($data);
}
all of these were done based on a tutorial all it works only when i remove the #extends('layouts.app') , line, or if i remove the "defer" in on app.blade file.
but when i do that all of my style layout is getting messed up. and is there a solution for this without removing existing code. because all existing codes are important.
try this in script
$('input.typeahead:search').typeahead({

A chart Js error issue are occured in my Laravel other page?

when I created a chart in my dashboard is working fine. But after when I go to another page like the post page, Then this chart error occurred. how can I solve this.
I have use this footer page in all pages. This footer shows an error in other page.
Undefined variable: chart (View: C:\wamp64\www\AdBlog\resources\views\admin\layouts\footer.blade.php)
And this is my Footer page for all admin page
<footer class="main-footer">
<div class="pull-right hidden-xs">
<b>Version</b> 2.3.8
</div>
<strong>Copyright © 2019-{{ Carbon\carbon::now()->year }} NS Tech.</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>
This is my controller page for 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
]);
}
}
web.php
//Admin Routes (web.php):
Route::group(['namespace' => 'Admin'], function(){
Route::get('admin/home','HomeController#index')->name('admin.home');
//Route::resource('admin/post','Admin\PostController'); -> uses this if not resource controller
//User routes
Route::resource('admin/user','UserController');
//Role routes
Route::resource('admin/role','RoleController');
//Permission routes
Route::resource('admin/permission','PermissionController');
//Post routes
Route::resource('admin/post','PostController');
//tag routes
Route::resource('admin/tag','TagController');
//category routes
Route::resource('admin/category','CategoryController');
//Admin Routes 1
Route::get('admin-login','Auth\LoginController#showLoginForm')->name('admin.login');
// Admin Routes2 copy 1,2 from Router.php auth code and edit yourself
Route::post('admin-login', 'Auth\LoginController#login');
});
add this in footer.blade.php to check if the current route name is admin.home
#if(Route::currentRouteName() == 'admin.home')
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js" charset="utf-8"></script>
{!! $chart->script() !!}
{!! $linechart->script() !!}
#endif
more info about Accessing The Current Route
Hope this helps!

Calling dynamic components in Vue JS with laravel

I'm trying to build an application on Laravel 5.4 and Vue JS 2.0 I'm having a set of components which are being used in specific page only, right now I'm defining the components globally and using the components tag in blade file, as I said lot components are of no use, so my mix file is getting bigger and I think this might slow down my page rendering. I'm looking for a solution where I can call components dynamically in blade file. Following is my app.js file:
Vue.component('NavBar', require('./components/NavBar.vue'));
Vue.component('HomeBanner', require('./components/HomeBanner.vue'));
Vue.component('PageFooter', require('./components/Footer.vue'));
Vue.component('Categories', require('./components/Categories.vue'));
Vue.component('SubCategory', require('./components/SubCategory.vue'));
const app = new Vue({
el: '#app'
});
I've a master blade file which have following HTML codes:
<div id="app">
<nav-bar></nav-bar>
#yield('content')
<div class="clearfix"></div>
<page-footer></page-footer>
</div>
<!-- Core Scripts for Vue Components -->
<script src="{{ asset('js/app.js') }}"></script>
and suppose in index.blade.php I've
#extends('layouts.master')
#section('title', 'HomePage')
#section('content')
<home-banner></home-banner>
#endsection
and in categories page I'm having:
#extends('layouts.master')
#section('title', 'Select your category')
#section('content')
<categories></categories>
#endsection
any suggestion how to achieve this.
Try this:
Create a new file, say, partial.js at the same level of your app.js with this:
window.Vue = require('vue');
Vue.component('categories', require('./components/Categories.vue'));
new Vue({
el: '#testing'
});
Add the partial.js to the elixir webpack in gulpfile.js. Should look like this:
elixir(mix => {
mix.sass('app.scss')
.webpack('app.js')
.webpack('partial.js');
});
Then in the blade file you want to have this enclose the 'category' tag between a div with id='testing'
After that, import the partials.js script like this:
<script src="/js/partials.js"></script>
I believe the importing here has to be done AFTER using the category component.
Your categories page should end up like this:
#extends('layouts.master')
#section('title', 'Select your category')
#section('content')
<div id='testing'>
<categories></categories>
</div>
<script src="/js/partials.js"></script>
#endsection
Try it out and let me know, that's how I solved a similar problem in the past. Cheers!

how to solve routeProvider issues with angular js sample?

I have just started trying out angular js and using the egghead.io videos. One of the samples is about routeProvider. I am using vs.net 2012 to run it but cant get it to display any of the templates or messages when I hit:
http://localhost/app.html/pizza
This is the sourcecode inside of app.html:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script>
// Create a new module
var app = angular.module("app", []);
app.config(function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: "app.html",
controller: "AppCtrl"
})
.when('/pizza', {
template: "yum"
})
});
app.controller("AppCtrl", function ($scope) {
$scope.model = {
message: "this is my app"
}
});
</script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css">
<div ng-app="app" ng-controller="AppCtrl">
</div>
Modified from JoeyP's post to make it work:
index.html
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script>
// Create a new module
var app = angular.module("app", []);
app.config(function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: "app.html",
controller: "AppCtrl"
})
.when('/pizza', {
templateUrl: "yum.html" // there was a typo here in the OP
})
.otherwise( {
redirectTo: '/'
});
});
app.controller("AppCtrl", function ($scope) {
$scope.message= "this is my app";
});
</script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css">
<div ng-app="app">
<div ng-view></div>
</div>
app.html
<div>
Go get some pizza! {{message}}
</div>
yum.html
<p>
MMMM, pizza
more pizzaaaaaaaa
</p>
Note: The code need to be run on web-server (ex. Apache) to function.
app.html and yum.html are fetched by angular after the page has loaded. So in your example http://localhost/pizza should point to the page with the above code and yum.html (as well as app.html) should be located in the root of your project.
On load angular will download app.html if you hit "/" and yum.html if you hit "/pizza". Here's an example
index.html (excluding <html>,<head>,<body>, etc)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script>
// Create a new module
var app = angular.module("app", []);
app.config(function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: "app.html",
controller: "AppCtrl"
})
.when('/pizza', {
template: "yum.html" // there was a typo here in the OP
})
});
app.controller("AppCtrl", function ($scope) {
$scope.model = {
message: "this is my app"
}
});
</script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/4.3.2/css/foundation.min.css">
<div ng-app="app">
<div ng-view></div>
</div>
app.html
<div>
<p ng-bind="model.app"><p>
<a ng-href="/pizza">Go get some pizza!</a>
</div>
yum.html
<p>
MMMM, pizza
</p>
The ng-controller attribute isn't needed because you defined the controllers in the routes. You do need the ng-view attribute somewhere in the main html file so angular knows where to insert the template.
John from egghead.io really needs to update this section of his tutorial.
See this answer:
Failed to instantiate module [$injector:unpr] Unknown provider: $routeProvider
you need to add this dependency:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
var app = angular.module("app", ['ngRoute']);
P.S. template: "yum" is totally valid, as in template: "<p>yum</p>"
(JoeyP thinks you're trying to do templateUrl: "yum.html")

Ember not updating the view on model change

This fiddle has the starter kit recreated, with and extra button that alters the model.
http://jsfiddle.net/UjacC/1/
However, when clicking change, the array changes, but the view is not being updated. Why?
<title>Ember Starter Kit</title>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
<button id="btnChange">change model</button>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{#each item in model}}
<li>{{item}}</li>
{{/each}}
</ul>
</script>
<script>
$(document).ready(function(){
console.log(stuff);
$("#btnChange").click(function(){
stuff.push("d");
console.log("change",stuff);
});
});
</script>
</body>
App = Ember.Application.create();
var stuff = ["a","7","b","c"];
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return stuff;
}
});
Instead of stuff.push you need to use Embers pushObject which will notify listeners of an object that there was a change to it.
EDIT:
Here's the updated jsfiddle: http://jsfiddle.net/UjacC/2/

Resources