I'm following the dataviz -> bar_charts -> grouped_data example from Kendo.Mvc.Examples that groups by stock symbols and displays closing values by date.
I'm trying to do the same thing and group by sTypeLabel and display dValue by dtDate and it's not working. I think it has something to do with the read.Action, but I'm not sure how to make it work. My example is so simple. When I look at the Kendo.Mvc.Examples it uses an action of _StockData in Scatter_Charts controller, which I see returns Json(ChartDataRepository.StockData()). Do I need to create an Action to do something? Is there documentation on this somewhere?
First my Model class:
public class TimeBasedTrendsGraphModel
{
public int ID { get; set; }
public DateTime dtDate { get; set; }
public string sTypeLabel { get; set; }
public double dValue { get; set; }
}
My controller:
public class TimeBasedTrendsGraphController : Controller
{
private MOSTestDBContext db = new MOSTestDBContext();
public ViewResult Index()
{
return View(db.TimeBasedTrendsGraph.ToList());
}
I'm using MOSTestDBContext, which created the SQL Server database MOSTest, in table TimeBasedTrendsGraphModels, with rows:
ID dtDate sTypeLabel dValue
1 2012-01-01 00:00:00.000 CourtesyDriver 5
2 2012-01-01 00:00:00.000 VanDrivers 10
3 2012-01-01 00:00:00.000 LaneCapt 15
4 2012-01-01 00:00:00.000 LotMaint 20
5 2012-01-01 00:00:00.000 LotCoord 25
6 2012-01-01 00:00:00.000 ServiceTruck 5
This repeats for 2012-01-02, 2012-01-03, and 2012-01-04 with the same data, increasing ID's, for testing
My view (Index.cshtml):
@model IEnumerable<MvcApplication5.Models.TimeBasedTrendsGraphModel>
@{
ViewBag.Title = "Index";
}
<h2>Time Based Trends Graph</h2>
<div class="chart-wrapper">
@(Html.Kendo().Chart(Model)
.Name("chart1")
.Title("Time Based Trends")
.DataSource(dataSource => dataSource
.Read(read => read.Action("_TBTData", "TimeBasedTrendsGraph"))
.Group(group => group.Add(model => model.sTypeLabel))
.Sort(sort => sort.Add(model => model.dtDate).Ascending())
)
.Series(series =>
{
series.Column(model => model.dValue)
.Name("value")
.Stack(true)
.GroupNameTemplate("#= group.value # (#= series.name #)");
})
.Legend(legend => legend
.Position(ChartLegendPosition.Bottom)
)
.CategoryAxis(axis => axis
.Categories(model => model.dtDate)
.Labels(labels => labels.Format("MM/DD/YY"))
)
.ValueAxis(axis => axis
.Numeric().Labels(labels => labels.Format("{0}"))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0}")
)
)
I'm trying to do the same thing and group by sTypeLabel and display dValue by dtDate and it's not working. I think it has something to do with the read.Action, but I'm not sure how to make it work. My example is so simple. When I look at the Kendo.Mvc.Examples it uses an action of _StockData in Scatter_Charts controller, which I see returns Json(ChartDataRepository.StockData()). Do I need to create an Action to do something? Is there documentation on this somewhere?
First my Model class:
public class TimeBasedTrendsGraphModel
{
public int ID { get; set; }
public DateTime dtDate { get; set; }
public string sTypeLabel { get; set; }
public double dValue { get; set; }
}
My controller:
public class TimeBasedTrendsGraphController : Controller
{
private MOSTestDBContext db = new MOSTestDBContext();
public ViewResult Index()
{
return View(db.TimeBasedTrendsGraph.ToList());
}
I'm using MOSTestDBContext, which created the SQL Server database MOSTest, in table TimeBasedTrendsGraphModels, with rows:
ID dtDate sTypeLabel dValue
1 2012-01-01 00:00:00.000 CourtesyDriver 5
2 2012-01-01 00:00:00.000 VanDrivers 10
3 2012-01-01 00:00:00.000 LaneCapt 15
4 2012-01-01 00:00:00.000 LotMaint 20
5 2012-01-01 00:00:00.000 LotCoord 25
6 2012-01-01 00:00:00.000 ServiceTruck 5
This repeats for 2012-01-02, 2012-01-03, and 2012-01-04 with the same data, increasing ID's, for testing
@model IEnumerable<MvcApplication5.Models.TimeBasedTrendsGraphModel>
@{
ViewBag.Title = "Index";
}
<h2>Time Based Trends Graph</h2>
<div class="chart-wrapper">
@(Html.Kendo().Chart(Model)
.Name("chart1")
.Title("Time Based Trends")
.DataSource(dataSource => dataSource
.Read(read => read.Action("_TBTData", "TimeBasedTrendsGraph"))
.Group(group => group.Add(model => model.sTypeLabel))
.Sort(sort => sort.Add(model => model.dtDate).Ascending())
)
.Series(series =>
{
series.Column(model => model.dValue)
.Name("value")
.Stack(true)
.GroupNameTemplate("#= group.value # (#= series.name #)");
})
.Legend(legend => legend
.Position(ChartLegendPosition.Bottom)
)
.CategoryAxis(axis => axis
.Categories(model => model.dtDate)
.Labels(labels => labels.Format("MM/DD/YY"))
)
.ValueAxis(axis => axis
.Numeric().Labels(labels => labels.Format("{0}"))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0}")
)
)
</div>