So here is my problem, and I'm sure it's something very simple. I'm relatively new to Web Development and I'm running into a little problem that I just can't figure out.
I have this code in an MVC view. . .
@{
var data = "";
var count = 1;
foreach (var item in ViewModel.Data)
{
data += count.ToString() + "," + item.Reading.ToString() + "\n";
count++;
}
}
I want to pass this 'data' variable to a very tiny script in order to create a graph using Dygraph. This is what I currently have, and believe should work, it doesn't though.
<script type="text/javascript">
g = new Dygraph(document.getElementById("readingGraph"), @data,{ labels: ["Sample Number", "Reading"] });
</script>
I know the script itself will work. If I hard-code some CSV values into a string where @data is, the graph pops up and everything is fine. With the @data there, the graph doesn't load and the script won't run at all (I placed an alert('hi') in there to see if it would pop-up, it didn't).
In addition, I know the string is being 'built' correctly because I have set break points in Visual Studio and checked.
Any help at all would be great guys. Thanks in advance.