Kendo UI Column Chart data binding not working - kendo-ui

In MVC application I am using Kendo column charts and I have the data as below.
Type
Percentage
Date
Color
A
25.5
2/12
#2456C7
B
70
2/13
#2456C8
B
50
2/14
#2456C8
B
55.5
2/15
#2456C8
A
60.3
2/13
#2456C8
I want to create a column chart with this data, chart should be categorized by Date and there should be multiple columns depending on the type.
I wrote the below code snippet but it isn't working, cannot see the data on UI.
#(Html.Kendo().Chart<EntitiesA.Report>
()
.Name("Report")
.Title("ReportA")
.Legend(legend => legend
.Position(ChartLegendPosition.Top)
)
.DataSource(dataSource => dataSource
.Read(read => read.Action("MethodReport", "ReportController"))
.Group(group => group.Add(model => model.Type))
.Sort(sort => sort.Add(model => model.Date).Ascending())
)
.Series(series =>
{
series.Column(model => model.Percentage)
.Name("#= group.value # (Percentage)").CategoryField("Date").ColorField("Color");
})
.Legend(legend => legend
.Position(ChartLegendPosition.Bottom)
)
.CategoryAxis(axis => axis
.Labels(labels => labels.Format("MM/DD"))
)
.ValueAxis(axis => axis.Numeric()
.Labels(labels => labels.Format("{0:N0}"))
.MajorUnit(20)
.Max(100)
.Line(line => line.Visible(false))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0:N0}")
)
)
I don't see any data in the graph it is blank how to fix it, am I missing any logic or piece of code.

If I'm not mistaken you want a Date axis, right? If so you can also specify that via the CategoryAxis configuration:
#(Html.Kendo().Chart<Report>()
.CategoryAxis(axis => axis
.Date()
.BaseUnit(ChartAxisBaseUnit.Days)
.Labels(labels => labels.Format("MM/dd"))
)
...
)
Passing some sample data renders the Chart - example

Related

Kendo Chart category axis fix number of labels

I have a kendo chart with date time series on x-axis as below but i wanted to fix the number of labels on the axis. Could you please help me on this how to acheive.
#(Html.Kendo().Chart(Model.ParameterValueList)
.Name("chart")
.Title("Chart Title")
.DataSource(ds => ds
.Group(group => group.Add(model => model.Parameter.Name))
)
.Series(series =>
{
series.Line(Model.ParameterValueList).CategoryField("ReceiveTime").Field("Value").Stack(false);
})
.CategoryAxis(axis => axis
.Categories(model => model.ReceiveTime).Date().RoundToBaseUnit(true)
.Labels(l => l.Rotation(-45).Format("dd MMM yyyy hh:mm:ss").Step(2))
.MajorGridLines(x=>x.Step(5))
.MajorTicks(x=>x.Size(5))
)
.Legend(legend => legend
.Visible(true).Position(ChartLegendPosition.Right)
)
.ChartArea(a => a.Width(800).Height(250))
.Tooltip(t => t.Visible(true).Template("${series.name} : ${value}"))
)

Kendo Grid with client CRUD, cancel remove row, can not set the ID properly

I have a Kendo Grid in a form with editable information and I would like the information save with one submit. It has CRUD functions and it is inline editable. All the save and edit works fine. However, whenever I add a new row->update->edit->cancel, the row got removed. There is a lot of articles say that it is the ID issue of each record. I add the
e.model.set('id', newId); e.model.set('CommentsID', newId);
in the SaveEvent, but it doesnt get changed. I looked one of the post in stack, one of them has the same issue:
Kendo UI MVC inline client-side grid - clicking cancel removes row. Not the model ID issue
But there are two issues for me(maybe I am wrong): one is the Guid that it generates is converted to string while my CommentsID is an int; Second, which the one that I mentioned above, I can not change the value of a model using e.model.set().
Since the only information I care about is the comment, I am wondering if there is any way that I can put a dummy ID to make it work so that the Cancel button won't remove the row when it is editing.
I also checked several links, but still didn't see any good solution.
Here is my code for the view:
#(Html.Kendo().Grid((IEnumerable<EE.BusinessLayer.ProviderLogic.POCO.CommentPOCO>)Model.Comments)
.Name("Comments")
.Columns(columns =>
{
columns.Bound(c => c.CommentsID).Hidden();
columns.Bound(c => c.ModifiedDate).Title("").Width(300).ClientTemplate("#=kendo.format(\"{0:MM/dd/yyyy hh:mm tt}\",kendo.parseDate(ModifiedDate))#" + "<br> #=UserName#");
columns.Bound(c => c.Comment).Title("").EditorTemplateName("TextAreaTemplate").ClientTemplate("<div style='max-width:465px;'>#=Comment#</div>").HtmlAttributes(new { style="max-width:470px;"});
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.Events(e => e.Edit("editEvent").Save("saveEvent"))
.ToolBar(toolbar => toolbar.Create().Text("Add Comment"))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(ds => ds
.Ajax()
.Model(m => {
m.Id(p => p.CommentsID);
m.Field(p => p.CommentsID);
m.Field(p => p.ProviderID).Editable(false);
m.Field(p => p.ModifiedDate).Editable(false);
m.Field(p => p.ModifiedUserID).Editable(false);
m.Field(p => p.Comment).Editable(true);
})
.Create(update => update.Action("GridNullFunction", "Provider"))
.Update(update => update.Action("GridNullFunction", "Provider"))
.Destroy(update => update.Action("GridNullFunction", "Provider"))
.ServerOperation(true)
)
)

Kendo MVC batch editing change row color or focus

I am a new babie for Kendo UI for MVC, I am trying to customise row color when doing batch editing for a grid, I looked in the internet but couldn't find any info. After editing a cell for batch editing grid by default Kendo add a small red spot at the top left hand side of the cell , what I want to achieve after editing any cell the whole row for that record change change it color. I would like to change the row to green for example to give the user more visibility what row have been edited before click save. I would really app if someone could help me.
code
#(Html.Kendo().Grid<MvcKendo.Models.Availablity>().Name("grid")
.Columns( columns => {
columns.Bound(c => c.Id);
columns.Bound(c => c.TimeFrom);
columns.Bound(c => c.TimeTo);
})
.DataSource(datasource => datasource.Ajax().PageSize(5)
.Read("GetDataAvailablity","Home"))
.ClientDetailTemplateId("template")
)
<script id="template" type="text/kendo-tmpl">
#(Html.Kendo().TabStrip()
.Name("tabStrip_#=Id#")
.SelectedIndex(0)
.Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
.Items(items =>
{
items.Add().Text("TimeSheet Details").Content(#<text>#TimeSheetDetails()</text>);
})
.ToClientTemplate()
)
#helper TimeSheetDetails()
{
#(Html.Kendo().Grid<MvcKendo.Models.TimeSheet>()
.Name("grid_#=Id#")
.Events(e => {
e.DataBound("onDataBound");
e.Change("ChangeEvent");
})
.Columns(columns =>
{
columns.Bound(t => t.Id);
columns.Bound(t => t.WardName);
})
.Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
.Editable(editable => editable.Mode(GridEditMode.InCell))
.ToolBar(tb=>tb.Save())
.DataSource(dataSource => dataSource
.Ajax().Batch(true)
.PageSize(5)
.Model(model=>model.Id(x=>x.Id))
.Read(read => read.Action("GetDataTimeSheet", "Home", new { Id = "#=Id#" }))
.Update(update => update.Action("Editing_Update", "Home"))
.Events(events => events.Error("error_handler"))
)
.Pageable().Sortable().ToClientTemplate()
)
![enter image description here][2]}
You can make use of the save event in Kendo grid to achieve this
C#
.Events(events => events.Save("onSave")
Javascript
function(e) {
$(e.container).closest("tr").css("background-color","lightgreen");
}
Here's the fiddle for the sample in JS

Kendo UI Grid Editor Template Ajax Drop Down displays value field not text field

I've got a hierarchical Kendo UI Grid (MVC Server Helpers) where one of the columns is a FK lookup that is backed with an Editor Template that does an AJAX lookup for the values. All of that works perfectly. What's not working is the column is showing the ID (Data Value Field from the drop down) and not the text (Data Text Field from the drop down).
Here's the Grid
#(Html.Kendo().Grid<ReceivingLogItemResponse>()
.Name("grid_#=GID#")
.Editable(e => e.Mode(GridEditMode.InCell))
.Sortable()
.Columns( c=>
{
c.Bound(i => i.GID).Hidden();
c.Bound(i => i.SerialNumber);
c.Bound(i => i.PartNumber);
c.Bound(i => i.Description);
c.Bound(i => i.Quantity);
c.Bound(i => i.ItemLotNumber).Title("Lot");
c.Bound(i => i.StatusId).Title("Status");
c.Bound(i => i.CategoryId).EditorTemplateName("ClientCategory");
c.Bound(i => i.LocationCode).Title("Location");
c.Bound(i => i.Comments);
c.Command(e => e.Custom("Add").Click("doItemAdd"));
})
.ToolBar(t => t.Save())
.Selectable(s => s.Type(GridSelectionType.Row))
.DataSource(dataSource => dataSource
.WebApi()
.Model(m =>
{
m.Id(i => i.GID);
m.Field(i => i.GID).Editable(false);
})
.Batch(true)
.ServerOperation(false)
.Read(read => read.Url(apiWrapper.receivingLogItemUrl() + "&receivingLogId=#=GID#").Type(HttpVerbs.Get))
.Update(u => u.Url(apiWrapper.receivingLogItemUpdateUrl()).Type(HttpVerbs.Post))
)
.Events(e => e.DataBound("itemDataBound"))
.ToClientTemplate()
)
And here's the EditorTemplate (ClientCategory)
#(Html.Kendo().DropDownList()
.Name("CategoryId")
.DataTextField("Code")
.DataValueField("CID")
.AutoBind(true)
.DataSource(ds => ds.Read(a => a.Url(apiWrapper.clientCategoryUrl()).Data("getClientCategoryID()"))))
The column displays the CID field until you enter it for editing, when the drop-down shows up it's populated with the correct values. When you go to another field it goes back to the CID.
What am I missing?

How can i show labels top of the columns kendo bar chart?

i'm trying to show value labels at top of the my chart's columns. I use Kendo UI.
I find this example but i havent done it. It's example:
Label Example
How can i show 100 and 20 values like in the example chart?
I have tried this code but i failed.
.Labels(labels => labels
.Visible(true).Format("C").Position(ChartBarLabelsPosition.OutsideEnd)
)
Here is my chart code. What can i do? Thanks for your help.
#(Html.Kendo().Chart(Model.TarihVM)
.Name("chart")
.Title(title => title
.Text("my chart title")
.Position(ChartTitlePosition.Top))
.Legend(legend => legend
.Visible(true)
.Position(ChartLegendPosition.Top))
.Series(series =>
{
series
.Column(model => model.deneme, categoryExpression: model => model.date).Name("deneme")
.Aggregate(ChartSeriesAggregate.Count);
series
.Column(model => model.digerdeneme, categoryExpression: model => model.date).Name("digerdeneme")
.Aggregate(ChartSeriesAggregate.Count);
series
.Column(model => model.KapsamDisi, categoryExpression: model => model.date).Name("Kapsam Dışı Dosyalar")
.Aggregate(ChartSeriesAggregate.Count);
})
.CategoryAxis(axis => axis
.Date()
.BaseUnit(ChartAxisBaseUnit.Months)
.MajorGridLines(lines => lines.Visible(true))
)
.Theme("metro")
.Tooltip(tooltip => tooltip
.Visible(true)
.Template("#= series.name #: #= value #"))
)
Please try below code in the label to resolve the issue:
.Labels(label => label.Visible(true)
.Format("{0:C0}")
.Position(ChartBarLabelsPosition.OutsideEnd))
Here is the answer thank you #D_Learning and #Nitin Mall!
Here is the solution if someone needs it:
.Series(series =>
{
series
.Column(model => model.deneme, categoryExpression: model => model.EvrakTarih)
.Name("deneme")
.Aggregate(ChartSeriesAggregate.Count)
.Labels(labels => labels.Visible(true).Format("C").Position(ChartBarLabelsPosition.OutsideEnd);
);

Resources