Fetching the values from a calculated field inside script tag
-
Hello,
I tried to implement canvasjs charts today. I have this code currently and the chart displays without a problem.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script type="text/javascript"> window.onload = function() { var carb = 30; var protein = 140; var fat = 20; var options = { exportEnabled: true, animationEnabled: true, title:{ text: "Macro Split Chart" }, data: [{ type: "pie", showInLegend: true, toolTipContent: "<b>{name}</b>: {y} g", indexLabel: "{name}: {y} g", legendText: "{name}", indexLabelPlacement: "inside", dataPoints: [ { y: carb, name: "Carb" }, { y: protein, name: "Protein" }, { y: fat, name: "Fat" } ] }] }; $("#chartContainer").CanvasJSChart(options); } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script> </body> </html>
However, If I replace
var protein = 140;
withvar protein = jQuery('.my-protein').val();
the chart stops working. Please help me with the correct syntax to fetch the values from a calculated field.Thanks. Happy xmas.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Fetching the values from a calculated field inside script tag’ is closed to new replies.