0

I am very new to reporting and mvc. Im trying to get my database data to populate my reports. The reports i have so far are hard coded but i have tried to use a raw query function which got from Return count using raw query, using Entity Framework and MVC to assist me. However i am still struggling to get the chart to display the database data.

report view:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("visualization", "1", { packages: ["corechart"] });
    google.setOnLoadCallback(drawChart);

    var sql = "SELECT COUNT(*) FROM dbo.School WHERE (SchoolName = Accountancy)";
    var total = _context.Database.SqlQuery < int > (sql).single();

    function drawChart() {                                
        var data = google.visualization.arrayToDataTable([
                       ['Task', 'Hours per Day'],
                       ['Accountancy', total],
                       ['Economics and Business', 2],
                       ['Law', 2],
                       ['Governance', 2],
                       ['Business', 7]
                   ]);

        var options = {
                          title: 'Sample (Until we figure out how to get database data)'
                      };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
    }
</script>

<div id="piechart" style="width:800px; height: 600px;"></div>
</div>

I tried to get the "Accounting" field to display but the chart didn't display the accounting total, it only displays the totals for the others (which are hard-coded)

Is there anything specific that needs to be coded to get this data ie like in the controller?.. just to remind I am very new to this

1 Answer 1

0

The question you're referencing is showing C# code. I know this can be confusing with the use of var (I'm not a big fan of var in C#). I'm not sure what the MVC 3 way of doing this would be, but you can't mix client and server-side code directly. In later versions of MVC, I think you can use Razor syntax to bind the server-side query result to your client-side javascript code.

An additional piece of advice: Take baby steps. You're jumping into a lot of concepts all at once if you've never done anything like this. You need to learn SQL, Entity Framework, Asp.net-mvc, Javascript, and the Google Charts API all at once to pull this off.

First try just to display the number on the page before trying to display a complicated interactive chart. For that matter, before you can do that you need to learn how to pull data from SQL into memory on your server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.