Graph using ACF the_field() only showing in first 2 posts

Question

I am trying to add a graph on my wordpress website using a custom field via ACF. I call the field using the_field() then build the chart with anychart using the field as the input. However, the charts are only being generated for the first two posts and not any else.

I tried changing the data input to the hardcoded values that are in the custom field and that works fine, so there is some issue calling it programmatically. This is within the single.php file.

Does anyone know why this problem exists and why it happens for all posts except the first two?

Here is the code and images of the problem (first image has the post where it works, but in the second you can see the graph is not loaded properly)

In the custom field, the text is in the following format:
[["stringa",0.5],["stringb",0.2],["stringc",7]]

https://imgur.com/a/IXlz0yQ

<!-- word map  -->

<script src="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script>

<script src="https://cdn.anychart.com/releases/v8/js/anychart-tag-cloud.min.js"></script>

<script>

anychart.onDocumentReady(function () {

var data = <?php get_field('wordmap_scores'); ?>;                                        

var chart = anychart.tagCloud(data);

chart.angles([0])
chart.colorRange(false);
chart.colorRange().length('80%');

chart.container("wordmap_display");
chart.draw();
});
</script>
0
Y Ahmed 4 months 0 Answers 16 views 0

Leave an answer