Home › forums › Using CanvasJS › Dynamic lines in graph
Tagged: canvas, graph, Line, value, ViewBag
This topic contains 4 replies, has 2 voices, and was last updated by danielz 1 year ago.
Hello everyone, I am working with a line graph and I take the values for a query and I load them to the graph by means of a ViewBag, in this way I can use dynamic data.
What I can not do is that the number of lines and the names of these (in the property: ‘name’) can enter them dynamically and not fixed as I am doing now putting each line “Name”, my intention in load X number of lines each with its name, its values and properties dynamically, possibly through a for each, is it possible?
Can you kindly share sample project along with sample data over google-drive or onedrive so that we can understand your requirements better and help you out?
Yes, I uploaded the controller file where I take the data from the database and I save it in ViewBags and the page where I insert the data in the graphics, I hope that my problem is clearer now, thanks.
the link: https://drive.google.com/open?id=1gwEqTsEc9UYmbowO7QcTvyheZ84-ECqh
You can store dataSeries name in ViewBags just like how you are doing it for data and read it in view ViewData["name"] = item.name;.
ViewData["name"] = item.name;
If this doesn’t fulfill your requirements, kindly share working project along with sample data, so that we can look into it and help you out.
name: @ViewData [“nameExample”],
color: “# FFC371”,
in the parameter “name:” I put ViewData [“nameExample”] or @ViewData [“nameExample”] and it did not work. in the controller I put the value to the ViewData and if I inspect it I see that it maintains the value but I can not use it in the graph. If you see the code that I have, I have more than one line in the same graphic, but I have to define one by one its name and its values, therefore I can not dynamically show “X” lines without having to repeat the code as many times as lines want to show
You must be logged in to reply to this topic.