How do I use ViewBag as a datasource for an igDataChart
I need to make a line chart with 3 series
I already use model on the page
Hello Christian,
I am glad that you have been able to resolve your issue. If any additional questions arise don’t hesitate to contact me again.
I missed this JavaScript in my view
<script src="~/Scripts/IG/infragistics.dv.js"></script>
now it is working
Thank you for your patience.
One possible implementation is assigning AsQueryable list to the viewbag in the controller and then creating IEnumerable object in the view which fetches the information from the viewbag.
[controller]
public ActionResult Index()
{
List<StockMarketDataPoint> stockMarketData = new List<StockMarketDataPoint>
{…}
ViewBag.Chart = stockMarketData.AsQueryable();
return View();
}
[view ]
@{IEnumerable<StockMarketDataPoint> list = ViewBag.Chart;
@(Html.Infragistics().DataChart(list.AsQueryable()).ID("chart")
.Axes(axes =>
axes.CategoryX("xAxis");
axes.NumericY("priceAxis");
)
.Series(series =>
series.Financial("finSeries").XAxis("xAxis").YAxis("priceAxis")
.OpenMemberPath(item => item.Open)
.CloseMemberPath(item => item.Close)
.LowMemberPath(item => item.Low)
.HighMemberPath(item => item.High)
.VolumeMemberPath(item => item.Volume);
.DataBind()
.Render());
A sample is attached for your reference. Feel free to modify it and use it in your projects if needed.
If you need any additional assistance or if you have any further questions or concerns please let me know.
When I define an axis I get this error
Unhandled exception at line 23, column 21580 in http://localhost:55339/Scripts/IG/modules/infragistics.dvcommonwidget.js
0x800a01b6 - Der opstod en JavaScript-kørselsfejl: Objektet understøtter ikke egenskaben eller metoden 'name'
this line is marked :
;axis.name(val.name)
List<Intranet.mvc.Models.m_Besogstal_Uger> listen = ViewBag.Data_Uge;@(Html.Infragistics().DataChart(listen.AsQueryable()).ID("Graf_Uge").Width("1100px").Height("600px").Axes(axes =>{axes.NumericX("xAxis");axes.NumericY("yAxis");}).Series(series =>{series.Line("Entre").XAxis("xAxis").YAxis("yAxis").ValueMemberPath(item => item.Entre).ShowTooltip(true).TooltipTemplate("tooltipTemplate1").Thickness(5);series.Line("Gratister").XAxis("xAxis").YAxis("yAxis").ValueMemberPath(item => item.Gratister).ShowTooltip(true).TooltipTemplate("tooltipTemplate2").Thickness(5);}).DataBind().Render())
I change the datatable to a list
Thank you for your reply.
In order to be bound to the igDataChart data should be passed in one of the following formats: JSON, XML, JavaScript array or IQueryable<T> in ASP.NET MVC. Data structure in datatable is not a supported format. More information on requirements for igDataChart data binding could found at the following link: http://help.infragistics.com/Help/NetAdvantage/jQuery/2012.1/CLR4.0/html/igDataChart_DataBinding.html#_Ref321140964
If you have any additional questions regarding this issue feel free to contact us.