[英]ngx-charts custom tooltip
I'm trying to add a custom tooltip to heatmap cells in ngx-charts-heat-map
.我正在尝试向
ngx-charts-heat-map
中的热图单元格添加自定义工具提示。 However, the data I want to show is neither the series, nor the value, nor the name.但是,我要显示的数据既不是系列,也不是值,也不是名称。 It's coming from the source data object, but a different property that's available to me while populating each cell in each series.
它来自源数据 object,但在填充每个系列中的每个单元格时我可以使用不同的属性。
I'm aware of tooltipTemplate
and I'm already using that, but how can I access data in there that's not the value, name or series?我知道
tooltipTemplate
并且我已经在使用它,但是我如何访问其中不是值、名称或系列的数据?
Update This is in my html:更新这是在我的 html 中:
<ngx-charts-heat-map
[view]="view"
[scheme]="colourScheme"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[animations]="animations"
[trimXAxisTicks]="trimXAxisTicks"
[trimYAxisTicks]="trimYAxisTicks"
[legend]="showLegend"
[xAxis]="xAxis"
[yAxis]="yAxis"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
[tooltipDisabled]="tooltipDisabled"
[results]="heatmap"
(select)="onSelect($event)">
<ng-template #tooltipTemplate let-model="model">
<pre>{{model|json}}</pre>
</ng-template>
</ngx-charts-heat-map>
In my ts:在我的 ts 中:
showLabels = true;
animations = true;
xAxis = true;
yAxis = true;
showYAxisLabel = true;
showXAxisLabel = true;
tooltipDisabled = false;
xAxisLabel = "Environment";
yAxisLabel = "Framework";
rotateXAxisTicks = true;
trimXAxisTicks = false;
trimYAxisTicks = false;
showLegend = true;
colourScheme = {
domain: ["#C91414", "#E3071D", "#FF7E01", "#FFBE00", "#75AD6F", "#1D7044"],
};
heatmap = [
];
...
series.push({
name: f.name,
value: f.value,
tooltipText: `${ f.percentage }% - ${ f.number } foo`
});
On the frontend however, when rendering {{model|json}}
there is only series
, name
and value
, no tooltipText
.然而在前端,渲染
{{model|json}}
时只有series
、 name
和value
,没有tooltipText
。
Looking at https://github.com/swimlane/ngx-charts/blob/master/projects/swimlane/ngx-charts/src/lib/heat-map/heat-map-cell-series.component.ts#L78 I'm not sure how to get the tooltip to display the tooltipText
.看着https://github.com/swimlane/ngx-charts/blob/master/projects/swimlane/ngx-charts/src/lib/heat-map/heat-map-cell-series.component.ts#L78我我不确定如何让工具提示显示工具提示
tooltipText
。
I actually worked it out I'm ecstatic.我真的解决了我欣喜若狂。
HTML: HTML:
<ngx-charts-heat-map
[view]="view"
[scheme]="colourScheme"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[animations]="animations"
[trimXAxisTicks]="trimXAxisTicks"
[trimYAxisTicks]="trimYAxisTicks"
[legend]="showLegend"
[xAxis]="xAxis"
[yAxis]="yAxis"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
[tooltipDisabled]="tooltipDisabled"
[tooltipText]="tooltipText"
[results]="heatmap"
(select)="onSelect($event)">
</ngx-charts-heat-map>
TS: TS:
tooltipText(data): string {
return (JSON.parse(JSON.stringify(data))).cell.tooltipText;
}
Making sure that each series has a custom tooltipText
set, this then shows a heatmap with custom tooltip:确保每个系列都有一个自定义工具提示
tooltipText
集,然后显示带有自定义工具提示的热图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.