Laravel 5.5无法使用ConsoleTV的图表包呈现动态图表 [英] Laravel 5.5 cant render dynamic charts using ConsoleTV's chart package

查看:62
本文介绍了Laravel 5.5无法使用ConsoleTV的图表包呈现动态图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能生成来自数据库的数据?我可以渲染图表,但没有显示数据.但是,当我转储数据时,它向我显示了数据数组.帮助将不胜感激.谢谢.图表输出就在这里: https://imgur.com/a/eyCVxSn

Why I cant generate the data coming from my database? I can render the chart but there is no data shown. But when i dump the data it shows me the array of the data. Help would be appreciated. Thanks. Chart output right here: https://imgur.com/a/eyCVxSn

PS:我想在第二个数据库中获取数据.这就是为什么模型中有"mysql2"的原因.

PS: I want to get the data in my second database. Thats why there is 'mysql2' in the Model.

GraphController.php

GraphController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\DB;
use View;
use App\News;
use Charts;
use App\Graph;

class GraphController extends Controller
{
    /**
    * Display a listing of the resource.
    *
    * @return \Illuminate\Http\Response
    */
    public function index()
    {



        $graph = Charts::database(Graph::find(1),'line','highcharts')
        ->title('Tokens')
        ->ElementLabel('Coins Sold')
        ->Responsive(true)
        ->dimensions(1000,500)
        ->data(Graph::find(1));

        dd($graph);

        $news = News::all();


        // //dd($news);
        return View::make('coin.news', compact('graph','news'));
    }
}

Graph.php模型

Graph.php Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Auth;
use Cache;
use Charts;


class Graph extends Model
{
    //

    protected $connection = 'mysql2';
    protected $table = 'ico_stages';



}


graph.blade.php

graph.blade.php




@section('graph')



        {!! $graph->render() !!}



@endsection

app.blade.php

app.blade.php

stylesheets....

{!! Charts::assets() !!}

@yield('graph')

news...

scripts...

当我使用dd($ graph)时,它显示了这一点.我还可以在图表中看到要渲染的数据.

When I use dd($graph) it shows me this. I can also see the data that i want to render in my chart.

Database {#299 ▼
  +data: Graph {#306 ▼
    #connection: "mysql2"
    #table: "ico_stages"
    #primaryKey: "id"
    #keyType: "int"
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: false
    #attributes: array:18 [▼
      "id" => 1
      "name" => "Stage 1"
      "start_date" => "2019-05-11 21:29:00"
      "end_date" => "2019-11-30 21:29:00"
      "total_tokens" => 10000000
      "base_price" => 2.0
      "min_purchase" => 100
      "max_purchase" => 10000
      "soft_cap" => 0
      "hard_cap" => 0
      "display_mode" => "normal"
      "private" => 0
      "user_panel_display" => 0
      "sales_token" => 1496.0
      "sales_amount" => 2720.0
      "status" => "active"
      "created_at" => "2019-05-12 05:29:57"
      "updated_at" => "2019-06-19 06:02:55"
    ]
    #original: array:18 [▼
      "id" => 1
      "name" => "Stage 1"
      "start_date" => "2019-05-11 21:29:00"
      "end_date" => "2019-11-30 21:29:00"
      "total_tokens" => 10000000
      "base_price" => 2.0
      "min_purchase" => 100
      "max_purchase" => 10000
      "soft_cap" => 0
      "hard_cap" => 0
      "display_mode" => "normal"
      "private" => 0
      "user_panel_display" => 0
      "sales_token" => 1496.0
      "sales_amount" => 2720.0
      "status" => "active"
      "created_at" => "2019-05-12 05:29:57"
      "updated_at" => "2019-06-19 06:02:55"
    ]
    #changes: []
    #casts: []
    #dates: []
    #dateFormat: null
    #appends: []
    #dispatchesEvents: []
    #observables: []
    #relations: []
    #touches: []
    +timestamps: true
    #hidden: []
    #visible: []
    #fillable: []
    #guarded: array:1 [▶]
  }
  +date_column: "created_at"
  +date_format: "l dS M, Y"
  +month_format: "F, Y"
  +hour_format: "D, M j, Y g A"
  +language: "en"
  +preaggregated: false
  +aggregate_column: null
  +aggregate_type: null
  +value_data: []
  +id: null
  +customId: null
  +type: "line"
  +library: "highcharts"
  +title: "Tokens"
  +element_label: "Coins Sold"
  +labels: []
  +values: []
  +colors: []
  +responsive: true
  +gauge_style: "left"
  +view: null
  +region: "world"
  #suffix: ""
  +container: ""
  +credits: false
  +loader: true
  +loader_duration: 500
  +loader_color: "#000000"
  +background_color: "inherit"
  +template: "material"
  +one_color: false
  +legend: true
  +x_axis_title: false
  +y_axis_title: null
  +script: ""
  +html: ""
  +export: null
  +"height": 500
  +"width": 1000
}

推荐答案

在图形模板中呈现数据

$graph = view('graph')->with('graph', $graph); 

并将渲染的数据返回新闻中

And to return rendered data to news

return view('coin.news', compact('graph','news'));

最终密码

    $graph = Charts::database(Graph::find(1),'line','highcharts')
    ->title('Tokens')
    ->ElementLabel('Coins Sold')
    ->Responsive(true)
    ->dimensions(1000,500)
    ->data(Graph::find(1));



    $news = News::all();

    $graph = view('graph')->with('graph', $graph); 

    return view('coin.news', compact('graph','news'));

这篇关于Laravel 5.5无法使用ConsoleTV的图表包呈现动态图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆