Support

Account

Home Forums Backend Issues (wp-admin) Add ACF inside JS code

Unread

Add ACF inside JS code

  • Hi,
    I’ve created a chart. Each bar has a single value, given with JS. But I would like to modify that value and the number of bars with ACF (repeater field). Does anyone know how to do this?

    My code is below:

    <script type=”text/javascript” src=”https://www.gstatic.com/charts/loader.js”></script&gt;

    <div id=”chart_div” style=”width: 500px; height: 800px;”></div>

    <script type=”text/javascript”>
    google.charts.load(‘current’, {‘packages’:[‘corechart’]});
    google.charts.setOnLoadCallback(drawChart);

    function drawChart() {
    var sDate = ‘<?php the_field(‘start-date’); ?>’;
    var data = google.visualization.arrayToDataTable([
    [‘x’, 2020, 2020, 2026, 2026],
    [‘x’, 2018, 2018, 2020, 2020],
    [‘x’, 2020, 2020, 2024, 2024],
    [‘x’, 2019, 2019, 2023.75, 2023.75],
    [‘x’, 2022.25, 2022.25, 2024, 2024]
    // Treat first row as data as well.
    ], true);

    var options = {
    legend:’none’,
    vAxis: {direction: ‘-1’,
    format: ”,
    gridlines: { count: 9}

    }
    };

    var chart = new google.visualization.CandlestickChart(document.getElementById(‘chart_div’));

    chart.draw(data, options);
    }
    </script>

    See the code working

Viewing 1 post (of 1 total)

The topic ‘Add ACF inside JS code’ is closed to new replies.