I was wondering if maybe someone could help me get the syntax correct to format the DateTime values on my CategoryAxis? Currently, the closest I have gotten throws an InvaidCastException, but my value is definately a datetime datatype. Any help will be appreciated, my code is below:
HomeController.cs:
Index.cshtml:
HomeController.cs:
using MobileChart_WithDataBind.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MobileChart_WithDataBind.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
var myHist = new List<
ChartHist
>
{
new ChartHist() { LoginDateTime = Convert.ToDateTime("2/6/2013 12:00:00"), LoginDuration_Fail = 3, LoginDuration_Pass=2 },
new ChartHist() { LoginDateTime = Convert.ToDateTime("2/5/2013 12:00:00"), LoginDuration_Fail = 4, LoginDuration_Pass=2 },
new ChartHist() { LoginDateTime = Convert.ToDateTime("2/4/2013 12:00:00"), LoginDuration_Fail = 3, LoginDuration_Pass=2 },
new ChartHist() { LoginDateTime = Convert.ToDateTime("2/3/2013 12:00:00"), LoginDuration_Fail = 3, LoginDuration_Pass=2 }
};
return View(myHist);
}
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
}
Index.cshtml:
@model IEnumerable<
MobileChart_WithDataBind.Models.ChartHist
>
@{
ViewBag.Title = "Home Page";
}
@(Html.Kendo().Chart(Model)
.Name("chart")
.Title("Chart Title")
.SeriesDefaults(seriesDefaults => seriesDefaults.Column().Stack(false)
)
.Series(series =>
{
series.Column(model => model.LoginDuration_Pass).Name("Passed").Color("Lime");
series.Column(model => model.LoginDuration_Fail).Name("Failed").Color("Red");
})
.CategoryAxis(axis => axis
.Categories(model => model.LoginDateTime)
.Title("Time of Attempt")
.Date()
.Labels(labels => labels
.DateFormats(formats => formats.Hours("HH:mm"))
)
)
.ValueAxis(axis => axis
.Numeric().Labels(labels => labels.Format("{0:0.00}"))
.Title("Seconds")
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0} Seconds")
)
)
<
h2
>@ViewBag.Message</
h2
>
<
p
>
To learn more about ASP.NET MVC visit <
a
href
=
"http://asp.net/mvc"
title
=
"ASP.NET MVC Website"
>http://asp.net/mvc<;/
a
>.
</
p
>
<
ul
data-role
=
"listview"
data-inset
=
"true"
>
<
li
data-role
=
"list-divider"
>Navigation</
li
>
<
li
>@Html.ActionLink("About", "About", "Home")</
li
>
<
li
>@Html.ActionLink("Contact", "Contact", "Home")</
li
>
</
ul
>