Using CMS Plain Text Field with Chart.js

Try this:

<canvas id="myChart" width="400" height="400">
	<script>
    var wLabels = {{wf {&quot;path&quot;:&quot;test-label&quot;,&quot;type&quot;:&quot;PlainText&quot;\} }}; // insert webflow variable here
    var labels = "'" + wLabels.split( "," ).join( "','" ) + "'";
    console.log( labels );

		var ctx = document.getElementById('myChart');
		var myChart = new Chart(ctx, {
			type: 'bar',
			data: {
				labels: labels,
				datasets: [{
					label: 'Some Label',
					data: [10, 20, 30, 40, 50],
					backgroundColor: ["white","#A5DBFF","#B6E5F9","#D1F0FF","#8ED3FF"], 
				}]
			},
		});
	</script>
</canvas>

If you can enter that and republish the site I’ll take a look, a bit hard to troubleshoot second hand, but if I can see the console log that will be a good start.

1 Like