从 Javascript 更改步长值
Changing the Step value from Javascript
我在asp.net中有如下Kendo.Chart,需要在图表数据刷新时更改Step值
例如
.步骤(8)
至
.步骤(0)
我该怎么做?
@(Html.Kendo().Chart<GenericDateTimeValueDataPoint>()
.Name("trendchart_" + location.LocationId)
.Legend(legend => legend.Visible(false))
.ChartArea(chartArea => chartArea.Background("transparent")
.Height(276))
.AutoBind(false)
.DataSource(ds => ds.Read(read => read.Action("ProfileTrend", "Chart")
.Data(@<text>function (){ var selectedTimespan = $('#duration option:selected').val(); var startDateTime = $('#startDateTimePicker').val(); var endDateTime = $('#endDateTimePicker').val() ; return { locationGuid: '@location.LocationId', timespan: selectedTimespan, startDateTime: startDateTime, endDateTime: endDateTime, timeZoneOffset: window.currentTimeZoneOffsetInHours }}</text>))
.Events(ev => ev.RequestStart("viewModel.utilisationDataRequestStarted")
.RequestEnd("uViewModel.utilisationDataLoaded")))
.SeriesDefaults(series => series.Column().Overlay(ChartBarSeriesOverlay.None))
.Series(series => series.Column(model => model.CollectedValue, categoryExpression: model => model.DateTimeFormattedString)
.Gap(0.3)
.Name("Valve Open")
.Color(Lookups.GetColourAsHex(Colours.SilverGrey)))
.CategoryAxis(axis => axis.MajorGridLines(lines => lines.Visible(false))
.Labels(labels => labels.Format("{0:d}").Step(8))
.Categories()
.Title(title => title.Text(DisplayText.Get("Time"))))
.ValueAxis(axis => axis.Numeric().Labels(labels => labels.Format("{0}%")).Line(line => line.Visible(true)).Min(0).Max(100).Title(title => title.Text(DisplayText.Get("Utilisation")))).Tooltip(tooltip => tooltip.Visible(true).Template("#=dataItem.DateTimeFormattedString#<br />#= kendo.format('{0:N2}',value) #%")))
您可以向 dataBound
事件添加回调(每次数据绑定到您的图表时都会触发),然后在此回调中您可以 change/set step
属性。但是您需要从 kendo 图表调用 refresh
方法才能应用更改。
代码类似于以下内容:
//Your code
.Events(ev => ev.RequestStart("viewModel.utilisationDataRequestStarted")
.RequestEnd("uViewModel.utilisationDataLoaded")))
.DataBound("onDataBound")))
//Your code
//Javascript
function onDataBound(arg) {
var chart = $("ELEMENT_ID").getKendoChart();
chart.options.axisDefaults.labels.step = 2;
chart.refresh();
}
希望对您有所帮助。
我在asp.net中有如下Kendo.Chart,需要在图表数据刷新时更改Step值
例如
.步骤(8)
至
.步骤(0)
我该怎么做?
@(Html.Kendo().Chart<GenericDateTimeValueDataPoint>()
.Name("trendchart_" + location.LocationId)
.Legend(legend => legend.Visible(false))
.ChartArea(chartArea => chartArea.Background("transparent")
.Height(276))
.AutoBind(false)
.DataSource(ds => ds.Read(read => read.Action("ProfileTrend", "Chart")
.Data(@<text>function (){ var selectedTimespan = $('#duration option:selected').val(); var startDateTime = $('#startDateTimePicker').val(); var endDateTime = $('#endDateTimePicker').val() ; return { locationGuid: '@location.LocationId', timespan: selectedTimespan, startDateTime: startDateTime, endDateTime: endDateTime, timeZoneOffset: window.currentTimeZoneOffsetInHours }}</text>))
.Events(ev => ev.RequestStart("viewModel.utilisationDataRequestStarted")
.RequestEnd("uViewModel.utilisationDataLoaded")))
.SeriesDefaults(series => series.Column().Overlay(ChartBarSeriesOverlay.None))
.Series(series => series.Column(model => model.CollectedValue, categoryExpression: model => model.DateTimeFormattedString)
.Gap(0.3)
.Name("Valve Open")
.Color(Lookups.GetColourAsHex(Colours.SilverGrey)))
.CategoryAxis(axis => axis.MajorGridLines(lines => lines.Visible(false))
.Labels(labels => labels.Format("{0:d}").Step(8))
.Categories()
.Title(title => title.Text(DisplayText.Get("Time"))))
.ValueAxis(axis => axis.Numeric().Labels(labels => labels.Format("{0}%")).Line(line => line.Visible(true)).Min(0).Max(100).Title(title => title.Text(DisplayText.Get("Utilisation")))).Tooltip(tooltip => tooltip.Visible(true).Template("#=dataItem.DateTimeFormattedString#<br />#= kendo.format('{0:N2}',value) #%")))
您可以向 dataBound
事件添加回调(每次数据绑定到您的图表时都会触发),然后在此回调中您可以 change/set step
属性。但是您需要从 kendo 图表调用 refresh
方法才能应用更改。
代码类似于以下内容:
//Your code
.Events(ev => ev.RequestStart("viewModel.utilisationDataRequestStarted")
.RequestEnd("uViewModel.utilisationDataLoaded")))
.DataBound("onDataBound")))
//Your code
//Javascript
function onDataBound(arg) {
var chart = $("ELEMENT_ID").getKendoChart();
chart.options.axisDefaults.labels.step = 2;
chart.refresh();
}
希望对您有所帮助。