Home forums Using CanvasJS Just wanna share using Laravel and Canvas JS

Tagged: 

This topic contains 0 replies, has 1 voice, and was last updated by  herrygallery 6 months, 1 week ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #18314

    herrygallery
    Member

    Just wanna share. I use Laravel 5.5. So in my Controller:

    $data = Mymodel::select(‘id’,’tablecolumn1′, ‘tablecolumn2’)->orderBy(‘tablecolumn2’)->get();

    Using $data->toArray(); the result need to be converted to requirement of Canvas JS, so I just use the syntax str_replace as necessary ():

    $data = str_replace(‘”tablecolumn2″‘, ‘x’, $data);
    $data = str_replace(‘”tablecolumn1″‘, ‘y’, $data);
    $data = str_replace(‘”id”‘, ‘label’, $data);
    $data = str_replace(‘label:’, ‘label:”‘, $data);
    $data = str_replace(‘,y:’, ‘”,y:’, $data);

    Then pass the variable to the view :

    return view(‘pages.charts.canvasjs2’, [ ‘data’ => $data ]);

    Dont forget to delete $data->toArray(), it gives me error if not deleted.

    Then in view, in dataPoints, I just put the following :

    dataPoints: <?php echo $data; ?>

    And in the tooltip:

    toolTipContent: “<b>Label :{label}, Value of X:{x}, Value of Y:{y}”,

    Work like a charm :) …. Sweett….

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.