Hello,
I tried to implement canvasjs charts today. I have this code currently and I’m having problem with fetching the value of the calculated field.
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function () {
var carb = jQuery('.my-carb').val();
var protein = jQuery('.my-protein').val();
var fat = jQuery('.my-fat').val();
var options = {
animationEnabled: true,
title: {
text: "Macro Split Chart"
},
data: [{
type: "doughnut",
innerRadius: "40%",
showInLegend: true,
legendText: "{label}",
indexLabel: "{label}: #percent%",
dataPoints: [
{ label: "Carbohydrates", y: carb },
{ label: "Protein", y: protein },
{ label: "Fat", y: fat }
]
}]
};
$("#chartContainer").CanvasJSChart(options);
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script>
</body>
</html>
However, If I replace these var protein = jQuery('.my-protein').val();
with numeric values like these var protein = 33;
the chart works. Please help me with the correct syntax to fetch the values.
Thanks.