Lava is not defined at ajax in blade file
muazzamazaz opened this issue · 7 comments
What Version?
Run
composer show khill/lavacharts
if you don't know
Issue
I am having issue of lava object undefined in blade file for ajax call, however this same code in controller works fine for non-ajax code.
Controller Code (chart creation code)
$temps = Lava::DataTable();
foreach ($sensor_status as $sdata) {
$temps->addStringColumn('Type')
->addNumberColumn('Temp')
->addRow(['Temp', $sdata->temprature])
->addRow(['Humidity', $sdata->humidity]);
Lava::GaugeChart('Temps', $temps, [
'width' => 400,
'greenFrom' => 0,
'greenTo' => 69,
'yellowFrom' => 70,
'yellowTo' => 89,
'redFrom' => 90,
'redTo' => 100,
'majorTicks' => [
'Safe',
'Critical'
]
]);
}//
return $temps->toJson();
View Code
-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
$.ajax({
url:val,
type: "POST",
data:{data_id:d_id},
success:function(result)
{
lava.loadData('Chart1', result, function (chart) {
console.log(chart);
});
I suppose my docs aren't clear enough, but the chart has to be rendered once with a empty datatable with the correct structure. This way the ajax know how to fill the chart.
<div id="chart-div"></div>
// With Lava class alias
<?= Lava::render('ScatterChart', 'AgeWeight', 'chart-div') ?>
// With Blade Templates
@scatterchart('AgeWeight', 'chart-div')
for example, that would render the chart into the page (but also includes the script tag for lava.js!!)
This code for non-ajax call that is working fine. I have to display on ajax call using above code example you have given in doc
try wrapping the ajax call in lava.ready()
because I think your on page load call beats the google chain of getting everything loaded
I have tried that already but its not loading anything about lava at blade template file.
No, I didn' t call lava.js since its already in package installed. How to call this? which path? I have copied it to public/js and call it but no success.
I checked back through my issue history and I think this might be what we're looking for... #215