[英]Add aggregate function on tooltip in kendo chart
I am working with a kendo chart which has a date x-axis. 我正在使用具有日期x轴的剑道图表。 I have several points for different dates, but the x-axis shows only the per month view.
我有几个日期不同的点,但x轴仅显示每月视图。 I have set a custom aggregate function to display the LAST data point that corresponds to each month, ie
我设置了一个自定义聚合函数来显示与每个月相对应的LAST数据点,即
Data points are: 数据点是:
Jan 01 2014 - $1500 Jan 03 2014 - $2000 Jan 10 2014 - $75 2014年1月1日-1500美元2014年1月3日-2000美元2014年1月10日-75美元
Shown in the graph is Jan 2014 - $75 图中显示的是2014年1月-75美元
When I hover over these points I want to show a custom tooltip with some custom value related to each of these points. 当我将鼠标悬停在这些点上时,我想显示一个自定义工具提示,其中包含与每个点有关的一些自定义值。 The value shown in the tooltip is being generated by my business logic and I do not consider important to discuss it here.
工具提示中显示的值是由我的业务逻辑生成的,因此我不认为在此处进行讨论很重要。 Lets say that for the above mentioned values the tooltip I want to show is:
可以说,对于上述值,我要显示的工具提示是:
Jan 01 2014 - $100 Jan 03 2014 - $200 Jan 10 2014 - $300 2014年1月1日-100美元2014年1月3日-200美元2014年1月10日-300美元
However, when I hover over the aggregated point for the current month I expect the tooltip to show the value 'C' (because of my previous aggregate function). 但是,当我将鼠标悬停在当月的汇总点上时,我希望工具提示显示值“ C”(因为我以前的汇总函数)。 However the value shown is:
但是,显示的值为:
Jan 2014 - '$100' 2014年1月-'$ 100'
My question is. 我的问题是。 Is there a way to specify a custom aggregate function to my kendo tooltip?
有没有办法为我的kendo工具提示指定自定义聚合函数?
The code for the chart is: 该图表的代码为:
public class MyModel{
public DateTime Date {get; set;}
public double ShownValue {get; set;}
public double ToolTipValue {get; set;}
}
@(Html.Kendo().Chart(List<MyModel>)
.Name("myChart")
.DataSource(dataSource => dataSource
.Sort(s => s.Add(fc => fc.Date))
)
.SeriesDefaults(seriesDefaults =>
seriesDefaults.Line().Style(ChartLineStyle.Smooth)
)
.Series(series =>
{
series.Line(value => value.ShownValue, category => category.Date)
.Aggregate("selectLastPoint");
})
.CategoryAxis(axis => axis
.Labels(labels => labels.Rotation(0).Format("MMM 'yy"))
.Date()
.BaseUnit(ChartAxisBaseUnit.Months)
.Justify(false)
)
.ValueAxis(axis => axis.Numeric()
.Labels(labels => labels.Format("{0:c}"))
)
.Tooltip(t => t
.Visible(true)
.Format("{0:c}")
.Template("#= kendo.format('{0:C}',dataItem.TooltipValue) #")
))
The code to my aggregate function is: 我的聚合函数的代码是:
function selectLastPoint(values) {
return values[values.length - 1];
}
I hope you can help me. 我希望你能帮助我。 Greetings, Luis.
问候,路易斯。
Never mind I just found the answer. 没关系,我才找到答案。 On the aggregate function I am returning just the value of the current point.
在聚合函数上,我只返回当前点的值。 I am supposed to return the whole dataItem as follows:
我应该返回整个dataItem,如下所示:
function selectLastPoint(values, series, dataItems) {
return dataItems[dataItems.length - 1];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.