I need to refresh my PieChart using calculation made in my controller using a DatePicker.
Despite the update of the Viewbag used for the series in my controller, It seems that the series are not updated when refreshing the Chart.
Any suggestions ?
MyView :
@(Html.Kendo().DatePicker()
.Name("startDatepicker")
.Value(DateTime.Now.ToShortDateString())
.Events(e =>
{
e.Change("onStartDateChange");
}))
@(Html.Kendo().Chart()
.Name("chartWorkDuration")
.Title(title => title.Text("Working time - Total : " +
ViewBag.TotalWorkDuration.ToString() + "h")
.Position(ChartTitlePosition.Bottom))
.ChartArea(chart => chart.Background("transparent"))
.Series(series => series.Pie(ViewBag.arWorkDuration)
.Padding(0)
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0:N0}")
)
)
<script>
function
onStartDateChange() {
var
startDate = $(
"#startDatepicker"
).data(
"kendoDatePicker"
).value().toDateString();
$.ajax({
url:
'PlanningGraph/RefreshGraph'
,
cache:
false
,
data: {
startDate: startDate
},
success:
function
(xhr, textStatus) {
$(
"#chartWorkDuration"
).data(
"kendoChart"
).refresh();
}
});
});
}
</script>
My Controller
// Creation of my viewmodel elements
....
var workDuration = graphElementViewModels.Select(w => new
{
category = w.strCategory,
value = w.dblValue,
color = w.strColor
});
ViewDat
a["arWorkDuration"] = workDuration;