0 Replies - 733 Views - Last Post: 27 January 2014 - 07:21 AM Rate Topic: -----

#1 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 199
  • View blog
  • Posts: 1,682
  • Joined: 13-March 10

Passing information from MVC Controller to a script

Posted 27 January 2014 - 07:21 AM

I got the following script from Google website, and i am trying to populate the graph with the values from my List<Person>. The fields i am interested in are Age and MaxAge but i jave no idea how to pass the information to the script.

This is the View part of the MVC app. Model and Controller seem to be working fine.

@model List<Models.Person>


<html>
  <head><title>AWESeeeeeeeINE!</title>
    <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([
              ['Year', 'Sales', 'Expenses'],
              ['2004', 10, 400],
              ['2005', 1170, 460],
              ['2006', 660, 1120],
              ['2007', 1030, 540]
            ]);

            
            //THE BELOW CODE IS NOT WORKING
            @foreach(var item in Model){
                data.push(item.Age, item.MaxAge);
                
            }
        
              var options = {
                  title: 'Company Performance',
                  vAxis: { title: 'Year', titleTextStyle: { color: 'red' } }
              };

              var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
              chart.draw(data, options);
          }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1