I create a dictionary in the model, which has The City as Key and The numbers of Kids as Value (@Model.dictionary). I want to make the pie chart dinamically so How can I use the dicionary data instead of the static data in my drawChart function.
I hope you can help me, thanks a lot.
<html>
<head>
</head>
<body>
<div id="piechart_3d" style="width: 900px; height: 500px;"></div>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['City', 'Kids per Day'],
['LA', 100000],
['NY', 100000]
]);
var options = {
title: 'Kids per City',
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
</script>
</body>
</html>
You can create a javascript array using razor, using this answer that converts a
List
to arra,y you can convert fromDictionary
very easy:This will create
And you use it like this, with few modifications.