I’m using the Google chart on my website and I would like to pass a value to the javascript from my code behind c#. How can I do it?
The value of 0 in the sample below should be a calculated value from C#.
My javascript in the header:
google.load('visualization', '1', { packages: ['gauge'] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var BudgetData = google.visualization.arrayToDataTable
([
['Label', 'Value'],
['YTD', 0]
]);
var options = {
width: 350, height: 150,
max: 100, min: -100
};
//Budget
var chart = new google.visualization.Gauge(document.getElementById('BudgetGauge'));
chart.draw(BudgetData, options);
}
And then the graph is shown as:
div id=”BudgetGauge” style=”height: 100px;”>”
You can use the Register array declaration method in C# to register a java script array and then access it from Javascript.
in the page Load
then put the array in the arrayToDataTable method like this