Hi ,
i am in learning phase of asp.net mvc charts. i am able to see data in controller but it is not displayed in view. can you please help. thanks in advance
controller code
[HttpPost]
public ActionResult DisplayChart([DataSourceRequest]DataSourceRequest request, string item)
{
var result = Enumerable.Range(0, 50).Select(i => new Chart
{
bytes = i.ToString(),
OS = "Android" + i.ToString(),
protocol = "SMTP" + i.ToString(),
Device = i.ToString(),
IP = "10.97.216." + i.ToString(),
Location = "Location" + i.ToString(),
Network = "Telstra " + i,
VLAN = "VLAN " + i.ToString(),
ChartNumber1 = 10 + i,
ChartNumber2 = 20 + i.ToString(),
ChartNumber3 = 30 + i,
Year = "201"+ i.ToString()
});
if (item != null)
{
var children = result
.Where(p => p.Location == item)
.ToList();
return Json(children.ToDataSourceResult(request));
}
else
{
var children = result
.ToList();
return Json(children.ToDataSourceResult(request));
}
}
and cshtml code is
<div class="row">
<div class="col-xs-18 col-md-12">
<div class="demo-section k-content wide">
@(Html.Kendo().Chart<TelerikMvcApp1.Models.Chart>()
.Name("chart2")
.Title(" Sample Chart")
.Legend(legend => legend
.Position(ChartLegendPosition.Top)
)
.ChartArea(chartArea => chartArea
.Background("transparent")
)
.DataSource(ds => ds.Read(read => read.Action("DisplayChart", "Chart")))
.Series(series =>
{
series.Column(model => model.ChartNumber1).Name("ChartNumber1").CategoryField("Year");
series.Column(model => model.ChartNumber2).Name("ChartNumber2").CategoryField("Year");
series.Column(model => model.ChartNumber3).Name("ChartNumber3").CategoryField("Year");
})
.CategoryAxis(axis => axis
.Categories(model => model.Year)
)
.AutoBind(true)
.ValueAxis(axis => axis.Numeric()
.Labels(labels => labels.Format("{0:N0}"))
.MajorUnit(10)
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Template("#= series.name #: #= value #")
)
.Events(events => events
.SeriesClick("onSeriesClick")
.SeriesHover("onSeriesHover")
.DataBound("onDataBound")
.AxisLabelClick("onAxisLabelClick")
.PlotAreaClick("onPlotAreaClick")
.PlotAreaHover("onPlotAreaHover")
.Render("onRender")
.LegendItemClick("onLegendItemClick")
.LegendItemHover("onLegendItemHover")
.DragStart("onDragStart")
.Drag("onDrag")
.DragEnd("onDragEnd")
.ZoomStart("onZoomStart")
.Zoom("onZoom")
.ZoomEnd("onZoomEnd")
)
)
</div>
</div>
</div>
<script>
function onSeriesClick(e) {
console.log(kendo.format("Series click :: {0} ({1}): {2}",
e.series.name, e.category, e.value));
}
function onSeriesHover(e) {
console.log(kendo.format("Series hover :: {0} ({1}): {2}",
e.series.name, e.category, e.value));
}
function onDataBound(e) {
console.log("Data bound");
}
function onAxisLabelClick(e) {
console.log(kendo.format("Axis label click :: {0} axis : {1}",
e.axis.type, e.text));
}
function onPlotAreaClick(e) {
console.log(kendo.format("Plot area click :: {0} : {1:N0}",
e.category, e.value
));
}
function onPlotAreaHover(e) {
console.log(kendo.format("Plot area hover :: {0} : {1:N0}",
e.category, e.value
));
}
function onRender(e) {
console.log("Render");
}
function onLegendItemClick(e) {
console.log(kendo.format("Legend item click :: {0}",
e.text));
}
function onLegendItemHover(e) {
console.log(kendo.format("Legend item hover :: {0}",
e.text));
}
function onDragStart(e) {
console.log("Drag start");
}
function onDrag(e) {
console.log("Drag");
}
function onDragEnd(e) {
console.log("Drag end");
}
function onZoomStart(e) {
console.log("Zoom start");
}
function onZoom(e) {
console.log(kendo.format("Zoom :: {0}", e.delta));
// Prevent scrolling
e.originalEvent.preventDefault();
}
function onZoomEnd(e) {
console.log("Zoom end");
}
//$(function () {
// $(document).bind("kendo:skinChange", updateTheme);
//});
//function updateTheme() {
// $("#chart2").getKendoChart().setOptions({ theme: kendoTheme });
//}
</script>