I want to add a new property to my Object. But it adds the property in double-quotes and the object is not able to initialize well. Here is my code in the JSFiddle.
Thanks for any suggestion in advance.
var chart;
function myFunction(incoming_data) {
var lcl = JSON.parse(JSON.stringify(incoming_data));
var headertxt = lcl.title_dynamic;
console.log(headertxt);
var chartCfg = {
zoomEnabled: true,
axisX: {
title: "chart updates every 2 secs",
crosshair: {
enabled: true,
snapToDataPoint: true
}
},
axisY: {
crosshair: {
enabled: true,
snapToDataPoint: true,
valueFormatString: "#,##0"
}
},
toolTip: {
shared: true
},
legend: {
dockInsidePlotArea: true,
verticalAlign: "top",
horizontalAlign: "right"
}
};
chart = new CanvasJS.Chart("chart-container", chartCfg);
chart.options.title = headertxt;
console.log(chart.options);
chart.render();
}
var json_val = {"title_dynamic":"{text:\"Header Tay\"}"};
myFunction(json_val);
<div id="chart-container" style="height: 300px; width: 100%;">
</div>
<div style="margin-top:16px;color:dimgrey;font-size:9px;font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration:none;"></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/canvasjs.stock.min.js"></script>
EDIT: I attached the code snippet.