如何渲染 Lavacharts 的 blade 模板?

How to render the blade templates of Lavacharts?

我是这个包的新手:khill/lavacharts。所以我尝试在他们的文档中测试他们的一些示例。

BarChart的例子中我们可以看到这些代码:

$lava = new Lavacharts; // See note below for Laravel

$votes  = $lava->DataTable();

$votes->addStringColumn('Food Poll')
      ->addNumberColumn('Votes')
      ->addRow(['Tacos',  rand(1000,5000)])
      ->addRow(['Salad',  rand(1000,5000)])
      ->addRow(['Pizza',  rand(1000,5000)])
      ->addRow(['Apples', rand(1000,5000)])
      ->addRow(['Fish',   rand(1000,5000)]);

$lava->BarChart('Votes', $votes);

return view('sample', compact(['lava'])); // I add these line


我尝试在视图中呈现 BarChart

方法一

@barchart('Food Poll', 'poll_div')

没有渲染发生/没有条形图。它只在我的视图中显示 @barchart('Food Poll', 'poll_div')

方法二

{!! Lava::render('BarChart', 'Food Poll', 'poll_div') !!}

{!! $lava->render('BarChart', 'Food Poll', 'poll_div') !!}

它向我显示错误:

BarChart('Food Poll') was not found.


有人知道如何在视图中呈现条形图吗?

用适当的名字称呼BarCharts

{!! $lava->render('BarChart', 'Votes', 'poll_div') !!}

并确保在 HTMl

中有一个 div 渲染图表的位置
<div id="poll_div"></div>

希望对您有所帮助