Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lava is not defined at ajax in blade file #324

Open
muazzamazaz opened this issue May 4, 2020 · 7 comments
Open

Lava is not defined at ajax in blade file #324

muazzamazaz opened this issue May 4, 2020 · 7 comments

Comments

@muazzamazaz
Copy link

muazzamazaz commented May 4, 2020

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);
  });
@muazzamazaz muazzamazaz changed the title Lava is not defined at blade file Lava is not defined at ajax in blade file May 4, 2020
@kevinkhill
Copy link
Owner

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!!)

@muazzamazaz
Copy link
Author

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

@kevinkhill
Copy link
Owner

try wrapping the ajax call in lava.ready() because I think your on page load call beats the google chain of getting everything loaded

@muazzamazaz
Copy link
Author

I have tried that already but its not loading anything about lava at blade template file.

@kevinkhill
Copy link
Owner

kevinkhill commented May 4, 2020 via email

@muazzamazaz
Copy link
Author

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.

@kevinkhill
Copy link
Owner

I checked back through my issue history and I think this might be what we're looking for... #215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants