[英]Kendo UI for Angular Chart Get Selection?
I'm using Kendo for Angular and I can't seem to get the selection.我正在将 Kendo 用于 Angular,但似乎无法进行选择。 What I want seems like it should be simple.
我想要的似乎应该很简单。 I have a scatter line chart that is populated by points.
我有一个由点填充的散点线图。 I would like the user to be able to click on a single point and have it call a method with that point data.
我希望用户能够单击单个点并让它调用具有该点数据的方法。 What I will end up doing is displaying some additional detail about that point in another pane but really I just need to connect the point right now...
我最终要做的是在另一个窗格中显示有关该点的一些其他详细信息,但实际上我现在只需要连接该点...
Here is my code currently:这是我目前的代码:
<kendo-chart [pannable]="{ lock: 'y' }" [zoomable]="{ mousewheel: { lock: 'y' } }"
(select)="SelectEvent($event)"
(selectStart)="SelectEvent($event)">
<kendo-chart-title text="License Usage History"></kendo-chart-title>
<kendo-chart-legend position="right" orientation="vertical"></kendo-chart-legend>
<kendo-chart-category-axis>
<kendo-chart-category-axis-item [select]="Selection"></kendo-chart-category-axis-item>
</kendo-chart-category-axis>
<kendo-chart-series>
<kendo-chart-series-item *ngFor="let series of SeriesData"
width="{{series.LineWidth}}"
[color]="series.Color"
[opacity]="series.Opacity"
style="normal"
type="scatterLine" (selectstart)="SelectEvent('start')"
(select)="SelectEvent('test')"
[data]="series.DataPoints"
name="{{ series.Name }}"
[markers]="{ visible: series.ShowMarkers }">
<kendo-chart-series-item-tooltip>
<ng-template let-value="value">
{{value.y}} - {{value.x | date:'medium'}}
</ng-template>
</kendo-chart-series-item-tooltip>
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>
I have tried a couple things.我已经尝试了几件事。 First I tried subscribing to
(select)
and (selectstart)
in several places, but I don't ever get anything (right now that event handler is just logging the argument to the console and I never get anything).首先,我尝试在几个地方订阅
(select)
和(selectstart)
,但我什么也没得到(现在事件处理程序只是将参数记录到控制台,我什么也没得到)。
I also tried to use the category axis [select]
property as shown above.我还尝试使用类别轴
[select]
属性,如上所示。 In the .ts file that property is defined like this:在 .ts 文件中,该属性定义如下:
public Selection: any = {
from: new Date(new Date().setDate(new Date().getDate() - 30)),
to: new Date()
};
This actually works when it initially loads and shows a selection slider.这实际上在它最初加载并显示选择滑块时起作用。 However when I load my data in it goes away and I no longer have selection available.
但是,当我加载我的数据时,它消失了,我不再有可用的选择。 I even tried resetting it in that method but no luck, it still disappears.
我什至尝试用这种方法重置它,但没有运气,它仍然消失了。 Here is the code for getting my data:
这是获取我的数据的代码:
this.sessionService.GetSessionHistoryForCustomer(customerId, codeOption.ReferencedObject, this.Start, this.End).subscribe(dps => {
const series = this.CreateSeries(dps, codeOption.ReferencedObject);
series.forEach(x => this.SeriesData.push(x));
this.Selection ={
from: this.Start,
to: this.End
};
});
So how in the world do you get the selection?那么你到底是如何获得选择的呢? Ideally I would like to NOT use the selection range sliders but I can make that work if I have to I guess.
理想情况下,我不想使用选择范围滑块,但如果我想我可以做到这一点。 I really would just like to have the user click on a marker and get that selection...
我真的很想让用户点击一个标记并获得那个选择......
Ok so after talking with Telerik support a bit, this is actually handled in the seriesClick event on the chart itself.好的,在与 Telerik 支持人员交谈后,这实际上是在图表本身的seriesClick事件中处理的。 The arguments for this event (
SeriesClickEvent
type) have a dataItem
property that will be your background data item and you can do what you need to with it from there.此事件的参数(
SeriesClickEvent
类型)有一个dataItem
属性,它将成为您的背景数据项,您可以从那里对它执行所需的操作。
For completeness here is the relevant portion of my updated html:为了完整起见,这里是我更新的 html 的相关部分:
<kendo-chart [pannable]="{ lock: 'y' }"
[zoomable]="{ mousewheel: { lock: 'y' } }"
(seriesClick)="PointSelected($event)">
...the other stuff...
</kendo-chart>
And the .ts function:和 .ts 函数:
PointSelected(e: SeriesClickEvent) {
const dataPoint = e.dataItem as LicenseUseDataPoint;
...Do stuff with the point...
}
The only unfortunate part is that currently there is no way to change the marker for that point to make it show the selection in the chart itself.唯一不幸的部分是,目前无法更改该点的标记以使其在图表本身中显示选择。 I put in a request to add that for the future but it's not there now.
我提出了一个要求,为将来添加它,但现在不存在。 Bummer but not a deal killer in my case.
在我的情况下,无赖但不是交易杀手。 Thanks Telerik support for the info.
感谢 Telerik 对信息的支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.