asp.net - Can't build chart with data from database -
i can't build chart data database. tried this, don't work
controller:
public actionresult chart() { return partialview("_chart"); }
in main view:
img src="@url.action("chart")"/>
partial view (_chart.cshtml):
@using testproject.models; @{ datetime[] xval = new datetime(); decimal[] yval = new decimal(); testprojectcontext db = new testprojectcontext(); var deals = d in db.dealsdirectory select d; deals.tolist().foreach(x => xval.add(x.date)); deals.tolist().foreach(y => yval.add(y.price)); var chart = new chart(width: 600, height: 400) .addtitle("Зависимость цены от времени") .addseries( name: "usd", xvalue: xval, yvalues: yval, charttype:"line") .write(); }
your code has basic syntax problem prevent code compile!
the below snippet not valid !
datetime[] xval = new datetime(); decimal[] yval = new decimal();
you can not assign datetime
object array/collection of datetime
s
you can use implicit variable declaration along linq query expression.
this should work
@{ var db = new testprojectcontext(); var xval = db.dealsdirectory.select(g => g.date).toarray(); var yval = db.dealsdirectory.select(g => g.price).toarray(); var chart = new chart(width: 600, height: 400) .addtitle("Зависимость цены от времени") .addseries( name: "usd", xvalue: xval, yvalues: yval, charttype:"line") .write(); }
Comments
Post a Comment