Monday, May 22, 2017

merge two javascripts into one foreach

I have javascript in my laravel blade view. Im wondering if i can merge these two scripts into one. Script display graph in each bootstrap tabs.

Script first:

var chart1 = AmCharts.makeChart( "chart_visits", {
        "dataProvider": [
            @foreach($results as $result)
                {
                    "date": "",
                    "value": ''
                },
            @endforeach
        ]
    } );

Script second:

var chart1 = AmCharts.makeChart( "chart_visits", {
        "dataProvider": [
            @foreach($results as $result)
                {
                    "date": "",
                    "value": ''
                },
            @endforeach
        ]
    } );

And this is my view:

<ul class="nav nav-tabs">
    <li>
        <a href="#bounce" data-toggle="tab"> Bounce rate </a>
    </li>
    <li class="active">
        <a href="#visits" data-toggle="tab"> Visits </a>
    </li>
</ul>

.

<div class="tab-content">
    <div class="tab-pane active" id="visits">
        <div class="chartdiv" id="chart_visits"></div>
    </div>

    <div class="tab-pane" id="bounce">
        <div class="chartdiv" id="chart_bounce"></div>
    </div>
</div>



via kuchar

Advertisement