我一直试图在一个线图表的工具提示中设置一个自定义标签,例如,修改HH:mm格式的分钟数(74分钟-> 1:14),但不幸的是,没有成功。将值显示为1.283(...3)并不是另一种选择。
有人知道如何保存x和y轴值(日期和数字),并修改工具提示显示值吗?
例如:https://swimlane.github.io/ngx-charts/#/ngx-charts/line-chart
而不是有一个工具提示显示颜色,国家名称和数字,->颜色,国家名称和字符串(数字> 3000?“高”:“低”;)
当前行为按预期工作。
期望行为显示自定义标签。
上面描述中问题链接的复制
更改行为的动机/用例是什么?能够自定义工具提示的内容
请告诉我们您的环境: OS: Win 10 x64,IDE: Eclipse
ngx-图表版本: 3.0.2
角版: 6.0.2
浏览器: all
语言: TypeScript 2.3.3
发布于 2018-07-31 11:51:01
您可以定义自己的工具提示模板,并在其中呈现任何您喜欢的HTML:
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="multi" ...>
<ng-template #tooltipTemplate let-model="model">
This is the single point tooltip template
<pre>{{model|json}}</pre>
</ng-template>
<ng-template #seriesTooltipTemplate let-model="model">
This is vertical line tooltip template
<pre>{{model|json}}</pre>
</ng-template>
</ngx-charts-line-chart>示例:https://swimlane.github.io/ngx-charts/#/ngx-charts/tooltip-templates
发布于 2019-05-17 20:09:27
以上解决方案不适用于多维图表(> 3),如叠加的水平/垂直条。
另一种适用于所有情况的简单方法是将tooltipText作为模型的一部分添加到属性中,如下所示:
export let multi = [
{
name: 'Germany',
series: [
{
name: '2010',
value: 7300000,
tooltipText: 't1'
},
{
name: '2011',
value: 8940000,
tooltipText: 't2'
}
]
}
];然后在标记中使用以下代码,
<ngx-charts-bar-horizontal-stacked
[view]="view"
[scheme]="colorScheme"
[results]="multi"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[legendPosition]="legendPosition"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
(select)="onSelect($event)">
<ng-template #tooltipTemplate let-model="model">
<div class="tooltip">
{{model.tooltipText}}
</div>
</ng-template>
</ngx-charts-bar-horizontal-stacked>发布于 2018-08-16 16:51:17
再次谢谢你。不想让这个问题得不到解决。问题是,代码片段在svg元素中。以下是最终版本:
<!-- This is single point tooltip template -->
<xhtml:ng-template #tooltipTemplate let-model="model">
<xhtml:div class="area-tooltip-container">
<xhtml:div *ngFor="let tooltipItem of model | json | durationHhmm" class="tooltip-item" style="text-align: center;">
<a style=" font-size: 1.2em;">{{tooltipItem.series}}</a><a *ngIf="tooltipShowTime==='DAY' || tooltipShowTime==='WEEK'" style=" font-size: 1.2em;"><br />{{tooltipItem.name | date: 'HH:mm'}} Uhr</a><a *ngIf="tooltipShowTime!=='DAY' && tooltipShowTime!=='WEEK'" style=" font-size: 1.3em; font-weight: 600;"><br />·</a><br /><a style=" font-size: 1.2em; font-weight: 600;">{{tooltipItem.name | date: 'dd.MM.yyyy'}} · </a><a style=" font-size: 1.3em; font-weight: 600;">{{tooltipItem.value}}</a>
</xhtml:div>
</xhtml:div>
</xhtml:ng-template>
<!-- Datapoints Y-Axis -->
<svg:g *ngFor="let series of data">
<svg:g ngx-charts-circle-series
[xScale]="xScale"
[yScale]="yScale"
[colors]="colors"
[data]="series"
[scaleType]="scaleType"
[visibleValue]="hoveredVertical"
[activeEntries]="activeEntries"
[tooltipDisabled]="tooltipDisabled"
[tooltipTemplate]="tooltipTemplate"
(select)="onClick($event, series)"
(activate)="onActivate($event)"
(deactivate)="onDeactivate($event)"
/>
</svg:g>https://stackoverflow.com/questions/51557129
复制相似问题